Style.Triggers vs ControlTemplate.Triggers

前端 未结 1 1013
离开以前
离开以前 2021-02-01 04:53

When should I choose Style.Triggers and when should I choose ControlTemplate.Triggers? Are there any benefits using one over another?

Say I hav

1条回答
  •  长情又很酷
    2021-02-01 05:18

    Update from Background does not change of button C# WPF the Button in windows 8 does use a ControlTemplate.Trigger for IsMouseOver so there are cases where ControlTemplate may need to be completely overwritten to get the desired functionality. So that would be a case where you need to use ControlTemplate triggers over Style triggers.

    You may not always need to override the default ControlTemplate. Say you have a control and you want all the MyTextControl to have a a blue Foreground when IsMouseOver is true and leave everything else as default. You could use something like this:

    
    

    If you wanted to use the ControlTemplate.Triggers you would need to copy the default MyTextControl Template or else you would end up with no visual.

    Aside from that I think the only difference is that Style.Triggers has a lower precedence than ControlTemplate.Triggers (Precedence documentation). But that would only matter if you use both trigger types.

    0 讨论(0)
提交回复
热议问题