在嵌套在 ScrollViewer 中时,当调整具有跨越 Width="*"的 ColumnDefinition 的 DataGrid(或任何其他具有列的控件)中的列大小时,将出现这种奇怪的行为,其中 ColumnDefinitions也会调整大小。
下面的 XAML 示例展示了这种行为。
有谁知道这里发生了什么以及为什么会发生? ColumnDefinitions 甚至具有固定的宽度,但它们仍在调整大小...
<Window.Resources>
<x:Array x:Key="PointList" Type="{x:Type Point}">
<Point X="1" Y="4" />
<Point X="2" Y="3" />
<Point X="3" Y="2" />
<Point X="4" Y="1" />
</x:Array>
</Window.Resources>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Background="Red" Grid.Column="0" Content="Something 1" />
<Label Background="Green" Grid.Column="1" Content="Something 2" />
<Label Background="Blue" Grid.Column="2" Content="Something 3" />
<DataGrid ItemsSource="{StaticResource PointList}" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" />
</Grid>
</ScrollViewer>
最佳答案
我假设会发生这种情况,因为在测量期间,ScrollViewer 会报告两个维度的无限空间(使用您的滚动条设置)。
关于wpf - DataGrid 列调整大小,调整 Grid ColumnDefinitions 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6826672/