简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM