如何使 Style.Triggers 触发要应用的不同命名样式 [英] How to make Style.Triggers trigger a different named style to be applied
本文介绍了如何使 Style.Triggers 触发要应用的不同命名样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有以下内容:
<Style TargetType="{x:Type TextBox}">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="Gray" />
<Style.Triggers>
<Trigger Property="IsFocused" Value="true">
<Setter Property="BorderBrush" Value="Green" />
<Setter Property="BorderThickness" Value="2" />
</Trigger>
</Style.Triggers>
</Style>
这很好用,这里没有什么太大的问题,但这是一个相当简单的案例.如果我想将 IsFocused 样式状态列为显式样式,会发生什么情况如何将该样式引用为 IsFocused 样式,即
This works fine and there is nothing too much wrong here, but it is a fairly simple case. What happens if I want to have the IsFocused style state listed as a exsplicit style how do reference that style as being the IsFocused style, i.e.
<Style x:key="ActiveStyle" TargetType="{x:Type TextBox}">
<Setter Property="BorderBrush" Value="Green" />
<Setter Property="BorderThickness" Value="2" />
</Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="Gray" />
<Style.Triggers>
<Trigger Property="IsFocused" Value="true">
-- Here I want to reference ActiveStyle and not copy the copy the setters
</Trigger>
</Style.Triggers>
</Style>
推荐答案
我不认为您可以,但是您可以通过这种方式重用样式:
I don't think you can however, you can reuse a style this way :
<Style x:Key="ActiveStyle" TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="IsFocused" Value="true">
<Setter Property="BorderBrush" Value="Green" />
<Setter Property="BorderThickness" Value="2" />
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource ActiveStyle}">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="Gray" />
</Style>
我没有看到其他解决方案:(
I don't see another solution :(
这篇关于如何使 Style.Triggers 触发要应用的不同命名样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文