基本 WPF 问题:如何添加自定义属性触发器?
我正在使用 Expresion Blend 3 并在我的项目中创建了一个新的用户控件。如果触发该用户控件的自定义属性(如列表中所示的属性),我希望故事板能够运行。
我了解到您需要一个依赖属性,但我的理解有限。这是我以属性“IsAwesome”为例设置的基本代码。
Partial Public Class simpleControl
Public Sub New()
MyBase.New()
Me.InitializeComponent()
End Sub
Public Shared ReadOnly IsAwesomeProperty As DependencyProperty = _
DependencyProperty.Register("IsAwesome", GetType(Boolean), GetType(simpleControl))
Public Property IsAwesome() As Boolean
Get
Return DirectCast(Me.GetValue(IsAwesomeProperty), Boolean)
End Get
Set(ByVal value As Boolean)
Me.SetValue(IsAwesomeProperty, value)
End Set
End Property
End Class
但是,我的属性没有显示在该列表中。我缺少什么?或者我的整个方法都是错误的? 任何帮助或建议将不胜感激!
干杯
I am using Expresion Blend 3 and created a new user control in my project. I want a storyboard to run if a custom property of that user control is triggered like with the ones shown here in the list..
I learnt you need a dependency property, but my understanding there is limited. Here's the basic code I set up with property "IsAwesome" as an example..
Partial Public Class simpleControl
Public Sub New()
MyBase.New()
Me.InitializeComponent()
End Sub
Public Shared ReadOnly IsAwesomeProperty As DependencyProperty = _
DependencyProperty.Register("IsAwesome", GetType(Boolean), GetType(simpleControl))
Public Property IsAwesome() As Boolean
Get
Return DirectCast(Me.GetValue(IsAwesomeProperty), Boolean)
End Get
Set(ByVal value As Boolean)
Me.SetValue(IsAwesomeProperty, value)
End Set
End Property
End Class
However, my property doesn't show in that list. What am I missing? Or is my entire approach wrong?
Any help or advice would be appreciated!
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我创建了一个新的 Wpf 项目。添加了一个新的 UserControl (UserControl1),其具有名为 Foo 的自定义依赖属性。
然后我打开 Blend 并将 UserControl1 的实例添加到 Window1。我右键单击 UserControl1 并说 EditTemplate |编辑副本。
这在 Window.Resources 中创建了我的用户控件模板的副本。在这个新模板中,我进入“触发器”面板并单击按钮添加新的属性触发器。
立即 Blend 默认在“激活时间”部分中选择我的属性。
替代文本 http://blog.BradCunningham.net/Images/ForumImages/CustomDPInBlend.png< /a>
您可以从这里获取我的小示例应用程序: http://blog.BradCunningham .net/SourceCode/ForumSamples/CustomDPInBlend.zip
I created a new Wpf project. Added a new UserControl (UserControl1) with a custom dependency property called Foo.
Then I opened Blend and added an instance of UserControl1 to Window1. I right clicked on UserControl1 and said EditTemplate | Edit a Copy.
This created a copy of my user control template in the Window.Resources. From within this new template I went up to the Triggers panel and clicked the button to add a new property trigger.
Right away Blend defaulted to selecting my property in the "Activated When" section.
alt text http://blog.BradCunningham.net/Images/ForumImages/CustomDPInBlend.png
You can grab my little sample app from here: http://blog.BradCunningham.net/SourceCode/ForumSamples/CustomDPInBlend.zip