样式未应用于WPF中的Datagrid标头。。。资源问题
我正在尝试为位于UserControl中的WPF数据网格使用一个标题样式。但我明白了: 找不到名为“{DataGridRowHeaderBackgroundStyle}”的资源。资源名称区分大小写。标记文件“WPF”中的对象“Microsoft.Windows.Controls.DataGridTextColumn”处出错;组件/视图/仪表板视图.xaml'第17行位置50 我将StaticResource更改为DynamicResource。没有错误,但样式不变 我的风格定义如下:样式未应用于WPF中的Datagrid标头。。。资源问题,wpf,datagrid,styles,Wpf,Datagrid,Styles,我正在尝试为位于UserControl中的WPF数据网格使用一个标题样式。但我明白了: 找不到名为“{DataGridRowHeaderBackgroundStyle}”的资源。资源名称区分大小写。标记文件“WPF”中的对象“Microsoft.Windows.Controls.DataGridTextColumn”处出错;组件/视图/仪表板视图.xaml'第17行位置50 我将StaticResource更改为DynamicResource。没有错误,但样式不变 我的风格定义如下: <S
<Style x:Key="DataGridRowHeaderBackgroundStyle" TargetType="{x:Type Primitives:DataGridColumnHeader}">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="#FF4C78F0" Offset="0.983"/>
<GradientStop Color="#FFEDF1FD" Offset="0.422"/>
<GradientStop Color="#FFACC0F7" Offset="0.069"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
作为资源的inside Window.xaml
<Window.Resources>
<ResourceDictionary Source="MainDebugResources.xaml" />
</Window.Resources>
这是在用户控件中
<data:DataGridTextColumn HeaderStyle="{StaticResource DataGridRowHeaderBackgroundStyle}" Header="Error" Width="*"
Binding="{Binding Text}" IsReadOnly="True" />
如果我做错了,请告诉我
谢谢请尝试将ResourceDictionary包括在内:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="MainDebugResources.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
我也遇到了同样的问题,经过多次实验后,我发现文本块样式优于网格列标题样式,但仅当指定为应用程序资源时,而不是指定为窗口资源时