如何在 Blend 中动态更改 UserControl 的外观?

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

我是 Blend 和 XAML 的新手,我有一个 UserControl,其中仅包含一个白色圆角矩形和一个带有黑色文本的标签。但是,当单击 UserControl 时,我希望矩形更改为蓝色,标签文本更改为白色,以模拟某种选定的外观。做这个的最好方式是什么?我不熟悉 XAML 所以我希望有一个解决方案,我可以在 Blend 中为它设置两个模板,然后在那个 UserControl 代码 window 中,有一个点击事件处理程序我只是告诉它切换到另一个模板。谢谢

实现此目的的最简单且对设计人员最友好的方法是 define two visual states. When the user clicks the control you can use the GotoStateAction 在状态之间切换。

使用视觉状态可以让您直观地定义所有内容,而无需深入研究代码或 XAML。

希望对您有所帮助。