在 WPF 中为 DataGridColumnHeader 创建自定义样式时,我应该使用什么“BasedOn”?
我应该为这种风格的 BaseOn
添加什么内容?
<Style
x:Key="DataGrid_ColumnHeaderStyle"
TargetType="wt:DataGridColumnHeader"
BasedOn="??????????"> <!-- I want this to be a reference to the default style -->
<Setter
Property="BorderBrush"
Value="{StaticResource Media_RaisedBorderBrush}" />
<Setter
Property="Background"
Value="{StaticResource Media_RaisedBackgroundBrush}" />
<Setter
Property="Foreground"
Value="{StaticResource Media_RaisedForegroundBrush}" />
</Style>
我不想覆盖整个默认样式,我只想用设置器更改一些属性。
编辑:
我知道如何使用BasedOn
,我只是不知道我的样式所基于的样式的名称或在哪里可以找到它。默认/内置样式的名称是什么?
编辑2:
好吧,我想这毕竟不是我需要的。无论我是否包含 BasedOn="{StaticResource {x:Type wt:DataGridColumnHeader}}"
似乎都没有任何区别。问题在于,仅设置 BorderBrush
、Background
和 Foreground
就会导致排序箭头消失。我不明白为什么会发生这种情况,因为排序箭头是在 ControlTemplate
中定义的,并且我没有编辑/覆盖 ControlTemplate
。我的排序箭头在哪里? (我肯定启用了排序,并且单击列标题确实会导致数据排序......它只是不显示箭头。)
What should I put for BasedOn
in this style?
<Style
x:Key="DataGrid_ColumnHeaderStyle"
TargetType="wt:DataGridColumnHeader"
BasedOn="??????????"> <!-- I want this to be a reference to the default style -->
<Setter
Property="BorderBrush"
Value="{StaticResource Media_RaisedBorderBrush}" />
<Setter
Property="Background"
Value="{StaticResource Media_RaisedBackgroundBrush}" />
<Setter
Property="Foreground"
Value="{StaticResource Media_RaisedForegroundBrush}" />
</Style>
I don't want to override the whole default style, I just want to change a handful of properties with setters.
EDIT:
I know how to use BasedOn
, I just don't know the name of the style I'm trying to base my style on or where to find it. What is the name of the default/built-in style?
Edit 2:
Okay, I guess this isn't what I needed after all. It doesn't seem to make any difference whether I include BasedOn="{StaticResource {x:Type wt:DataGridColumnHeader}}"
or not. The problem is that just setting the BorderBrush
, Background
, and Foreground
is causing the sort arrows to disappear. I don't understand why this is happening because the sort arrows are defined in the ControlTemplate
and I'm not editing/overriding the ControlTemplate
. Where are my sort arrows? (I definitely have sorting enabled, and clicking the column header does cause the data to sort...it just doesn't show the arrows.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
BasedOn="{StaticResource {x:Type TextBox}}">并且它将继承默认样式(这是针对 TextBox 的,但它适用于每个控件)。
BasedOn="{StaticResource {x:Type TextBox}}"> and it will inherit from the default style(this is for TextBox but it works for every control).
据我理解,您不需要将 BasedOn 指定为默认样式。也许如果你设置了 OverridesDefaultStyle 你就必须这样做。我相信默认样式仍然有效,只有您在样式设置器中指定的属性才会更改。
至于查找有关默认样式/模板的更多信息,一种方法是在 Blend 中打开项目,然后右键单击要查看默认模板的元素,然后选择“编辑模板...” ,然后选择编辑副本。
The way I understand it you don't need to specify the BasedOn to the default style. Maybe if you set OverridesDefaultStyle you would have to. I believe the default style will still hold true and only the properties you specify in your style setters will change.
As far as finding out more information about a default style / template, one way to do that is to open up your project in Blend and right click on the element you want to see the default template for and select "Edit Template...", then select Edit a Copy.