xaml wpf中的数据网格样式

时间:2014-01-12 21:29:24

标签: wpf wpfdatagrid

这是我的数据网格代码,

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

现在,如何在Style标签中包含最后2个属性。 例如,

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

提前致谢。

1 个答案:

答案 0 :(得分:1)

你应该将键命名为有意义的东西,现在称之为StyleX。将该名称与网格中的Style属性一起使用。

如果省略键名,则会将其视为该目标类型的默认样式。

您可以为Style使用相同的属性,但将它们放在Property和Value属性中。不要将DynamicResource用于静态属性。

您需要的代码:

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