【问题标题】:Is it possible to expand a xaml setter?是否可以扩展 xaml 设置器?
【发布时间】:2016-07-14 23:01:44
【问题描述】:

XAML 样式是否可以从具有设置器“模板”的样式继承,继承所有现有触发器并使用另一个触发器扩展它?

示例样式:

<Style x:Key="BigButton" TargetType="{x:Type RadioButton}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type RadioButton}">
                <ControLTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="Opacity" Value="1"/>
                    </Trigger>
                    <Trigger Property="IsPressed" Value="true">
                        <Setter Property="Background" Value="Red"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

我的大多数按钮都有这两个触发器的样式。 所以现在我的问题。 如果我有以下新样式:

<Style x:Key="BigButton" TargetType="{x:Type RadioButton}" 
  based on="{StaticResource BigButton}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType={x:Type RadioButton}">
                <ControlTemplate.Triggers>
                    <Trigger Property="IsEnabled" Value="true">
                        <Setter Property="Background" Value="White"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

使用这种样式,它会覆盖以前的模板设置器。 所以我的问题是: 有没有办法不覆盖以前的模板设置器,只在新样式中添加触发器?

我希望你能帮助我。 如有遗漏请填写

问候 理查德

我尝试过的:

基于

试图从控制模板中取出触发器

【问题讨论】:

  • 您的示例都缺少&lt;/Setter&gt;
  • 谢谢,我在示例中添加了它们
  • 触发器是 ControlTemplate 的一部分,所以不,您不能只添加它们而不覆盖模板。这是我对 XAML 的最大抱怨之一。
  • @ThomasLevesque 如果你创建一个答案,我会支持它

标签: xaml


【解决方案1】:

触发器是ControlTemplate 的一部分,所以不,你不能只添加它们而不覆盖模板(这对 IMO 来说很遗憾,但就是这样)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-15
    • 2010-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    相关资源
    最近更新 更多