首页 > 解决方案 > wpf datagrid itemscontrol gridsplitter dont move

问题描述

there is my code

<Grid Grid.Row="2" Margin="10,0,10,5">
            <Border BorderBrush="DarkGray" BorderThickness="1"></Border>
            <ScrollViewer BorderBrush="White" BorderThickness="10" Margin="1">
                <ItemsControl ItemsSource="{Binding DataViews,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.IsSharedSizeScope="True">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition></RowDefinition>
                                    <RowDefinition></RowDefinition>
                                </Grid.RowDefinitions>
                                    <DataGrid Grid.Row="0" MaxHeight="400" VerticalScrollBarVisibility="Auto" VerticalAlignment="Stretch" Margin="0,0,10,0" MaxColumnWidth="450"
                                          RowStyle="{StaticResource DataGridRowSql}" Style="{StaticResource DataGridStyleSQL}"
                                          ColumnHeaderStyle="{StaticResource StyleDataGridColumnHeaderDefault}" ItemsSource="{Binding}"
                                          IsReadOnly="{Binding RelativeSource={RelativeSource AncestorType=Page},Path=Locked}"
                                          RowEditEnding="DataGrid_RowEditEnding" AutoGeneratingColumn="DataGrid_AutoGeneratingColumn">
                                        <DataGrid.CommandBindings>
                                            <CommandBinding Command="Copy" Executed="CommandBinding_Executed"></CommandBinding>
                                        </DataGrid.CommandBindings>
                                        <DataGrid.InputBindings>
                                            <KeyBinding Key="C" Modifiers="Ctrl" Command="Copy"></KeyBinding>
                                        </DataGrid.InputBindings>
                                    </DataGrid>
                                <GridSplitter Grid.Row="1" Background="Red" Height="10" HorizontalAlignment="Stretch" ResizeDirection="Rows" ResizeBehavior="PreviousAndNext"></GridSplitter>
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel VerticalAlignment="Stretch"></StackPanel>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                </ItemsControl>
            </ScrollViewer>
        </Grid>

the problem is that everything is seen perfectly but when you drag the gridsplitter everything stays exactly as it is, nothing moves at all, where am I wrong?

标签: wpfdatagridscrollvieweritemscontrol

解决方案


尝试更改它,使您有 3 行,并且 gridsplitter 填充第 1 行。

像这样:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition></RowDefinition>
        <RowDefinition Height="10"/>
        <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>
    <GridSplitter Grid.Row="1" Background="Red" 
                  HorizontalAlignment="Stretch" 
                  ResizeDirection="Rows" 
                  ResizeBehavior="PreviousAndNext"/>

可能还有其他一些问题——因为里面有很多复杂的东西。然而。我只是在一个窗口中尝试了您的标记,但它在那里不起作用。

这样做:

    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition Height="10"/>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <GridSplitter Grid.Row="1" Background="Red" 
                      HorizontalAlignment="Stretch" 
                      ResizeDirection="Rows" 
                      ResizeBehavior="PreviousAndNext"/>
        <Rectangle Fill="Yellow"/>
        <Rectangle Fill="Lavender" Grid.Row="2"/>
    </Grid>
</Window>

推荐阅读