views:

213

answers:

2

I want to define a ToggleButton that appears with red foreground (for example) when checked, rather than the default appearance of a pressed button.

I see that the visual states are maintained as named elements inside the ToggleButton's control template.

What is the easiest way to replace/remove/customize a visual state WITHOUT redefining the entire template?

A: 

Have you tried creating your own controltemplate and set the "BasedOn" parameter to standard and then only changed what you needed?

andreas
+1  A: 

I realise this is very late, but I just ran into the same issue and figured out the solution myself, so hopefully this will be useful to someone...

After the template has been applied to a control (after the first measure/display cycle), you can access the instantiated template and its child components simply by using VisualTreeHelper.GetChild (myToggleButton, 0) - this will return the root object of the instantiated template's visual tree, from which you can add/remove/modify the child objects in its Children collection.

Obviously you're only changing the visual state of that instance of the control, not the template resource itself, so new controls created from the same template will still have the original visual appearance.

My realted question on this subject is here: http://stackoverflow.com/questions/2036879/

Duckboy
thats cool, I would like a XAML solution but hey, whatever works.
grennis