我有一个DataGrid,其中AutoGenerateColumns
设置为true(Columns
是动态生成的)我已将HorizontalAlignment
设置为Left
,以摆脱右边的额外Column
。
<DataTemplate x:Key="myTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="name" Margin="20,0,0,0" Grid.Row="0"/>
<TextBlock Text="name1" Margin="20,0,0,0" Grid.Row="1"/>
<SelectiveScrollingGrid Grid.Row="2">
<DataGrid x:Name="ProcessParameterGrid"
AutoGenerateColumns="True"
ItemsSource="{Binding Path=BindingProp}"
IsReadOnly="True"
HorizontalAlignment="Left"
Margin="20,0,0,10"
CanUserSortColumns="False"
CanUserReorderColumns="False"
HeadersVisibility="Column"
FrozenColumnCount="1"/>
</SelectiveScrollingGrid>
</Grid>
</DataTemplate>`
<ScrollViewer>
<CustomPanel>
<ItemsControl ItemsSource="{Binding Source={StaticResource RecipeDetailsCollectionViewSource}}"
VirtualizingStackPanel.IsVirtualizing="True">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl Content="{Binding}"
ContentTemplate="{StaticResource myTemplate}"
ScrollViewer.CanContentScroll="True"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</CustomPanel>
</ScrollViewer>
问题:
我需要冻结Column
的第一个Grid
,我需要DataGrid
使用父容器调整大小 - Grid
。
如果我明确地为Width
设置DataGrid
,则会显示右侧的额外Column
。我错过了什么?