xaml wpf中的数据网格样式

xaml wpf中的数据网格样式,wpf,wpfdatagrid,Wpf,Wpfdatagrid,这是我的数据网格代码 <DataGrid Name="dtLogView" Margin="10,10,10,10" ItemsSource="{Binding}" **RowBackground="Gray" AlternatingRowBackground="LightGray"** </Datagrid> 您应该将键命名为有意义的名称,现在称之为StyleX。将该名称与网格中的“样式”属性一起使用 如果省略键名,它将被视为该目标类型的默认样式 可

这是我的数据网格代码

<DataGrid Name="dtLogView"
   Margin="10,10,10,10"
   ItemsSource="{Binding}"
   **RowBackground="Gray"
   AlternatingRowBackground="LightGray"**
</Datagrid>

您应该将键命名为有意义的名称,现在称之为StyleX。将该名称与网格中的“样式”属性一起使用

如果省略键名,它将被视为该目标类型的默认样式

可以对样式使用相同的特性,但要将它们放在“特性”和“值”特性中。不要将DynamicSource用于静态属性

您需要的代码:

<Style TargetType="{x:Type DataGridRow}">
  <Setter Property="Background" Value="{StaticResource {x:Static SystemColors.WindowBrushKey}}" />
<Setter Property="AlterationBackground" Value="{StaticResource {x:Static SystemColors.WindowBrushKey}}" />
</Style>

<Style TargetType="{x:Type DataGridRow}">
  <Setter Property="Background" Value="{StaticResource {x:Static SystemColors.WindowBrushKey}}" />
<Setter Property="AlterationBackground" Value="{StaticResource {x:Static SystemColors.WindowBrushKey}}" />
</Style>