如何制作Style.Triggers触发要应用的其他命名样式 [英] How to make Style.Triggers trigger a different named style to be applied

查看:176
本文介绍了如何制作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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆