如何在混合中创建自定义控件的视觉状态?
我有一个从 Control
类派生的自定义控件。我希望这个自定义控件具有视觉状态。我如何通过 Blend 定义这些状态?如果我有用户控件或其他内置控件,则很容易做到这一点。但是我如何定义自定义控件的视觉状态。我只想使用 Blend,不想自己编写所有代码。
提前致谢 :)
I have a custom control that i have derived from the Control
class. I want this custom control to have visual states. How do i define these states through Blend? If i have a user control or some other inbuilt control it's very easy to do so. But how can i define visual states for custom control. I want to use Blend only and do not want to write all that code by myself.
Thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您通过扩展
Control
创建自定义控件时,您必须为其指定一个样式,该样式是您保存所有视觉状态的位置。如果您在 App.xaml 中添加适用于您的控件的样式,则可以设置其中包含视觉状态的 ControlTemplate。下面是一些示例 XAML,您可以将其添加到页面中,然后通过 Blend 编辑到您心中的内容。
(注意,未经测试的 XAML)
When you create a custom control by extending
Control
you must give it a style, this style is where you would hold all of your visual states.If you add a style in you App.xaml that applies to your control, then you can set the ControlTemplate which has the visual states inside of it. Here is some sample XAML that you can add to your page, then edit via Blend to your hearts content.
(Note, untested XAML)