Char Char - 1 month ago 8
C# Question

How to change the look of a UserControl dynamically in Blend?

I'm new to Blend and XAML, and I've got a UserControl containing just a white rounded off rectangle and a label with black text. However, when the UserControl is clicked, I want the rectangle to change to Blue and the label text to White, to emulate a sort of selected look. What is the best way to do this? I'm not familiar with XAML so I was hoping there'd be a solution where I can just set two templates for it in Blend, and then in that UserControl code window, have a click event handler where I just tell it to switch over to the other template. Thanks

Answer

The easiest - and designer friendliest - way to achieve this is to define two visual states. When the user clicks the control you can use the GotoStateAction to switch between the states.

Using visual states allows you to define everything visually without having to delve into code or XAML.

Hope it helps.