c# - WPF - creating a trigger to use a resource style -


I have a dialog with the button - Button text and functionality are dynamic and change according to the user's requirements. In most cases the button style is the default style, if the button is an OK button, then I would like to use the button with a different style. I tried to add a trigger that would change the button style according to Boolean property: (when Ikbutton = uses true "Redbutton Style")

   & Lt; / DataTrigger & gt; & Lt; /ControlTemplate.Triggers> & Lt; / ControlTemplate & gt; & Lt; /Button.Template>  
  • RedButtonStyle is a resource style that can be used in different projects for different button types, so soultion should be in my project and can not be in processing style on one's own.

But I get an exception when using this trigger

thanks

Can someone help me solve this problem? Or can suggest a suggestion to set the style dynamically?

Thanks

You can enter the trigger in your style:

  & lt; Style x: key = "Ok button style" & gt; & Lt; Style.Triggers & gt; & Lt; Data Trigger Binding = "{Binding ISOKButton}" value = "true" & gt; // OKButtonStyle & lt; / DataTrigger & gt; Whatever the property is different & Lt; Datatrigger binding = "{binding ISOKButton}" value = "wrong" & gt; // Set it back to default & lt; / DataTrigger & gt; & Lt; /Style.Triggers> & Lt; / Style & gt;  

Then style your button with OK button style.

If your OK button is to make it more like a normal style that you want all your buttons you want, then you can make it the basis just on a normal one:

  & lt; Style x: key = "Ok button style" based on = "{static resource general button style}" & gt;  

Comments