What I want to achieve is easily explained: change the background color of a wpf-tabitem in case it is selected (it should fit the window background). All other properties of the default control should stay the same.
我想要实现的目标很容易解释:如果选择了一个wpf-tabitem,就改变它的背景颜色(它应该适合窗口背景)。默认控件的所有其他属性应该保持不变。
The dump solution I came up with is to copy the whole default style into my ResourceDictionary
and replace the color #FFF9F9F9
in the following section:
我提出的转储解决方案是将整个默认样式复制到我的ResourceDictionary中,并在以下部分中替换颜色#FFF9F9F9:
<Trigger Property="Selector.IsSelected">
/* ..... cutting some lines here ....*>
<Setter Property="Panel.Background" TargetName="Bd">
<Setter.Value>
<SolidColorBrush>
#FFF9F9F9</SolidColorBrush>
</Setter.Value>
</Setter>
Obviously, I do not like this and tried to apply inheritance (BasedOn="{StaticResource {x:Type TabItem}}"
). This had no effect. Then I experimented with template settings. However, I failed to deal with the border in the default template, referenced avobe by "Bd". Adding the border to my ContentTemplated worked, but all other funcionalities of the default TabItem were gone (mouseover etc).
显然,我不喜欢这样,并尝试应用继承(BasedOn="{StaticResource {x:Type TabItem}}")。这没有影响。然后我尝试使用模板设置。但是,我没有处理默认模板中的边界,由“Bd”引用avobe。向我的contenttemplate添加边框成功了,但是默认选项卡项的所有其他功能都消失了(mouseover等)。
Can someone give me a hint how to change this color property without copying the whole default template? Any help appreciated!
有人能告诉我如何在不复制整个默认模板的情况下更改这个颜色属性吗?任何帮助表示赞赏!
1 个解决方案
#1
0
If the color is not linked to a property (like Background
) in the default template you will have to replace the template with an edited copy, there is no other (acceptable) way of changing it.
如果没有将颜色链接到默认模板中的属性(如背景),则必须用编辑好的副本替换模板,没有其他(可接受的)更改方法。
#1
0
If the color is not linked to a property (like Background
) in the default template you will have to replace the template with an edited copy, there is no other (acceptable) way of changing it.
如果没有将颜色链接到默认模板中的属性(如背景),则必须用编辑好的副本替换模板,没有其他(可接受的)更改方法。