Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
XML
<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:

XML
<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
Posted
Updated 15-Jul-16 0:00am

1 solution

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[^]
 
Share this answer
 
Comments
Evosoul04 15-Jul-16 7:18am    
Yeah, I guess you are right. I only found answer that says it is impossible.
Thanks for the answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900