如何向按钮添加额外的可绑定视觉状态组?

发布于 2024-09-15 13:54:24 字数 164 浏览 2 评论 0原文

我需要扩展一个按钮控件来添加一些额外的、可绑定的视觉状态。

我想创建的是一个附加的布尔属性,要绑定到它,这将在按钮上创建一个简单的视觉状态更改。对于这个例子,它可能只是一个根据布尔值改变颜色的附加边框。

所有现有的按钮行为应该完全独立于这组新的状态。

这可以做到吗?

I need to extend a button control to add some additional, bindable, visual states.

What I would like to create is an additional boolean property, to bind to, that will create a simple visual state change on the button. For this example, it could just be an additional border which changes colour according to the boolean value.

All the existing button behaviour should be entirely seperate from this new set of states.

Can this be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狼亦尘 2024-09-22 13:54:26

这当然可以做到。 这是一篇文章,将引导您完成整个过程您需要执行的步骤,并包括使用最终控件中显示的属性(除了那些用于保存状态的属性)扩展控件的附加信息。您需要的部分包括:

  1. 派生自 Button 的类(您的自定义控件类)
  2. 该控件的默认样式(位于 /themes/generic.xaml 中)。您可以从 Button 的通用样式开始,并向其中添加您的状态。
  3. 保存布尔值的依赖属性
  4. 保存两个新状态的新 VisualStateGroup
  5. 类中的一些代码将不断变化的状态与您定义的布尔值粘合在一起,可能是由用户交互等产生的。
  6. 您可能会发现更容易在 Blend 中编辑视觉状态,具体取决于您的过渡的复杂程度等。

This can certainly be done. Here's a post that walks you through the steps you'll need to take, and includes additional information for extending the control with properties (besides just those to hold state) that show up in the final control. The pieces you'll need are:

  1. A class that derives from Button (your custom control class)
  2. A default style for this control (which goes in /themes/generic.xaml). You can start off with Button's generic style and add your states to it.
  3. A dependency property that holds your boolean value
  4. A new VisualStateGroup that holds your two new states
  5. Some code in your class that glues together changing states with the boolean value you've defined, presumably resulting from user interaction, etc.
  6. You may find it's easier to edit the visual state in Blend, depending on how sophisticated your transitions will be, etc.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文