wpf datagrid itemscontrol gridsplitter 不要移动
wpf datagrid itemscontrol gridsplitter dont move
有我的代码
<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>
问题是一切都看得很清楚,但是当你拖动 gridsplitter 时,一切都保持原样,没有任何移动,我哪里错了?
尝试更改它,使您有 3 行,网格拆分器填充第 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 中尝试了您的标记,但它在那里不起作用。
这样做:
</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>
有我的代码
<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>
问题是一切都看得很清楚,但是当你拖动 gridsplitter 时,一切都保持原样,没有任何移动,我哪里错了?
尝试更改它,使您有 3 行,网格拆分器填充第 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 中尝试了您的标记,但它在那里不起作用。
这样做:
</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>