Search code examples
wpfdatagridscrollvieweritemscontrol

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?


Solution

  • Try changing it so you have 3 rows and the gridsplitter fills row 1.

    Like this:

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

    There may be some other issues - because you have a load of complicated stuff there with this inside it. However. I tried your markup just in a window and it doesn't work there.

    This does:

        </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>