我DataGrid
在我的 WPF 应用程序中使用 a 来显示一些数据。在应用程序加载时,有时 Grid 的列会变得很奇怪,左侧的“全选”按钮会消失,导致列分隔符不在列所在的位置。只有当用户尝试调整列的大小时,网格的布局才会正常。
我的 DataGrid 定义是:
<DataGrid Name="myList" AutoGenerateColumns="False" ItemsSource ="{Binding SortedView}" VirtualizingStackPanel.IsVirtualizing="False" ColumnWidth="Auto">
这是问题的屏幕截图以供说明:
这是 DataGrid 的完整 XAML 代码:
<DataGrid Name="myList" AutoGenerateColumns="False" ItemsSource ="{Binding SortedView}" VirtualizingStackPanel.IsVirtualizing="False" ColumnWidth="Auto">
<Interactivity:Interaction.Triggers>
<Interactivity:EventTrigger EventName="Sorting" >
<WPFCommon:InvokeDelegateCommandAction
Command="{Binding SortCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=InvokeParameter}" />
</Interactivity:EventTrigger>
</Interactivity:Interaction.Triggers>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="{x:Static p:Resources.Sensor}" Binding="{Binding SensorName, Mode=OneWay}" Width="Auto" />
<DataGridTextColumn Header="{x:Static p:Resources.Status}" CanUserSort="True" Binding="{Binding Classification, Mode=OneWay}" Width="Auto" />
<DataGridTextColumn Header="{x:Static p:Resources.Created}" Binding="{Binding CreatedDate, Mode=OneWay}" CanUserSort="True" Width="Auto" IsReadOnly="True" />
<DataGridTextColumn Header="{x:Static p:Resources.Last_Updated}" Binding="{Binding LastUpdated, Mode=OneWay}" CanUserSort="True" Width="*" IsReadOnly="True" />
</DataGrid.Columns >
</DataGrid>
如果有人知道如何DataGrid
在加载/更改时自动调整大小或刷新,那就太好了。
谢谢!