我的DataGrid的样式只有在选择一行后才会应用。这意味着在我单击一行后,所有行和单元格都会完全改变外观。
以下代码'修复'问题:
void Window_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
DataGridData.UnselectAll();
DataGridData.SelectedIndex = 0;
}
DataGrid的定义(SelectedItem在ViewModel中设置):
<DataGrid Grid.Row="1"
ItemsSource="{Binding Path=WASDs}"
SelectedItem="{Binding Path=SelectedWASD}"
x:Name="DataGridData">
我在名为DataGrid.xaml的File中为我的DataGrid定义了多个样式(Row,Column ...)。未加载的样式是隐式定义的:
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource {x:Type DataGridRow}}">
此文件作为最后一个ResourceDictionary加载到应用程序app.xaml中:
<Application.Resources>
<ResourceDictionary>
<!-- WPF 4.0 workaround -->
<Style TargetType="{x:Type Rectangle}" />
<!-- end of workaround -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary x:Name="FontSize" Source="..." />
<ResourceDictionary Source="..." />
<ResourceDictionary Source="DataGrid.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
我尝试过: