WPF 用户控件和 ICommand
我创建了一个 UserControl,里面有一个按钮,还有按钮的样式。该样式在鼠标悬停在触发器上时设置按钮背景。现在,我添加了 ICommand 类型的依赖属性,并将按钮命令设置为这个新属性。命令绑定工作正常,但是当自定义控件被禁用(canexecute = false)时,鼠标悬停在触发器上仍然会更改背景。
我尝试过像这样更改鼠标悬停触发器,但它不起作用:
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"/>
<Condition Property="IsEnabled" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Background" Value="Orange"/>
</MultiTrigger>
任何人都可以帮忙吗?
I have created a UserControl which has a button inside and also a style for the button. The style sets the button background upon a mouse over trigger. Now i've added an dependency property of type ICommand and sets the button command to this new property. The command binding works properly however when custom control is disabled (canexecute = false) the mouse over trigger still changes the background.
I've tried changing the mouse over trigger like this but it doesn't work:
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"/>
<Condition Property="IsEnabled" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Background" Value="Orange"/>
</MultiTrigger>
Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您在 Condition 中引用的 IsEnabled 属性是 Control 的属性,而不是 Button 的属性。因此控件已启用,这就是触发条件为真的原因。要访问该按钮,您可以尝试使用
相对源
标记扩展。你可以尝试这样的事情:
I think that the IsEnabled property you refer to in the Condition is the property of the Control, not the Button. So the Control is Enabled, and that's why the trigger conditions are true. To access the button you may try using
Relative Source
Markup Extension.You may try something like: