Page 1 of 1

Button and action for change the "style" (how to?)

Posted: 11 Mar 2018, 10:45
by Wanderer
I have basic button and I want change the button style after something happen. For example, if Label or any element get value 1, button change color scheme, and if value from element get back to 0, button get previous color scheme.
Idea to change color scheme is duplicated graphic but with diferent colors. And when value is 0, duplicated graphics are hidden, and when value is 1, then graphics will be hidden and duplicated visible.
Idea is bind visibility to the value, but button don't have value, and I have no idea how or where to bind it.
How to do this without codebehind? It is possible?

Re: Button and action for change the "style" (how to?)

Posted: 12 Mar 2018, 17:28
by sfernandez
You can for example bind Button.Tag property to the element that is receiving these values of 0/1.
Then you can use that from inside Button's ControlTemplate to enable the corresponding color scheme.

Would that work for you?

Re: Button and action for change the "style" (how to?)

Posted: 12 Mar 2018, 18:51
by Wanderer
Can you provide some example please? It is not necessary because at last I decide to use code behind (because I discover that I need more then 2 states, and values will be computed in codebehind), but for future examples it will be helpful. I bind visibility to the
<Canvas ... Visibility="{Binding visual_ok_visibility}">
<Canvas ... Visibility="{Binding visual_error_visibility}">
//...
This is inside button template. It will be working with Codebehind? This button is in UserControl.