我想为WPF数据网格设置样式,这似乎非常容易。据我了解,我必须具有以下代码:
<Style x:Key="DataGridColumnHeaderStyle" TargetType="{x:Type Custom:DataGridColumnHeader}" >
<Setter Property="Background" Value="#88800080" />
<Setter Property="Foreground" Value="White" />
</Style>
但是我的问题是..我应该在哪里放置这段代码,如何让数据网格知道使用上面的样式?
问候,
小号
最佳答案
将其放在xaml的资源中(本地或全局)。最简单的方法是将其放在当前xaml文件的本地资源中:
<Page Name="SomeName"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<Style x:Key="DataGridColumnHeaderStyle" TargetType="{x:Type Custom:DataGridColumnHeader}" >
<Setter Property="Background" Value="#88800080" />
<Setter Property="Foreground" Value="White" />
</Style>
</Page.Resources>
<!-- The rest of the xaml -->
</Page>