是否可以扩展xaml setter? [英] Is it possible to expand a xaml setter?
问题描述
大家好,
xaml样式是否可以从具有settertemplate的样式继承,继承所有现有触发器并将其扩展为另一个触发器?
示例样式:
< 样式 x:键 < span class =code-keyword> = BigButton TargetType = {x:Type RadioButton} >
< Setter 属性 = 模板 >
< Setter.Value >
< ControlTemplate TargetType = {x:输入RadioButton} >
< ControLTemplate.Triggers >
< 触发器 属性 = IsMouseOver 值 = true >
< Setter 属性 = 不透明度 值 = 1 / >
< / Trigger >
< 触发 属性 = IsPressed 值 = true >
< Setter 属性 = 背景 值 = 红色 / >
< / Trigger >
< / ControlTemplate.Triggers >
< / ControlTemplate >
< / Setter.Value >
< / Style >
我的大多数按钮都有这两个触发器的样式。
现在问我的问题。
如果我有以下新风格:
< 样式 x:键 = BigButton TargetType = {x:Type RadioButton} 基于 = {StaticResource BigButton} >
< < span class =code-leadattribute> Setter Property = 模板 >
< Setter.Value >
< ControlTemplate TargetType = {x:类型 RadioButton} >
< ControlTemplate.Triggers >
< 触发器 属性 = IsEnabled 值 = true < span class =code-keyword>>
< Setter 属性 = 背景 值 = 白色 / >
< /触发 >
< /ControlTemplate.Triggers >
< / ControlTemplate >
< / Setter.Value >
< / Style >
使用这种风格它会覆盖以前的模板设定器。
所以我的问题是:
有没有办法不覆盖以前的模板设定器而只是在新款式中添加触发器?
我希望你能提供帮助我。
如果有遗漏信息,请写下来
问候
Richard
我尝试过:
基于
试图从控制模板中获取触发器
我认为这是不可能的。您可以尝试将其他触发器添加到Style.Triggers中,并且根本不要触摸Template属性。在你的样本中,它应该可以工作。
c# - Style.Triggers vs ControlTemplate .Triggers - Stack Overflow [ ^ ]
Hello everyone,
Is it possible for a xaml style to inherit from a style with the setter "template", inherit all existing triggers AND expand it with another trigger?
Example Style:
<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>
</Style>
Most of my Buttons have style with these two triggers.
So now to my question.
If I have following new 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>
</Style>
With this style it overwrites the previous Template Setter.
So my question is:
Is there a way to NOT overwrite the previous Template Setter and only add the trigger in the new Style?
I hope you can help me.
If there are missing information please write it
Greetings
Richard
What I have tried:
Based On
Tried to get the triggers out of the controltemplate
I think it's impossible. You can try to put additional triggers into Style.Triggers and don't touch Template property at all. In your sample it should work.
c# - Style.Triggers vs ControlTemplate.Triggers - Stack Overflow[^]
这篇关于是否可以扩展xaml setter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!