根据其他控件中的属性更改属性 - WPF
当我的文本框的文本框属性 Validation.HasErrors
为 True
时,我想使用某种触发器将窗口中的按钮更改为 IsEnabled = False
代码>.
我可以使用按钮上的某种触发器来执行此操作吗?
如果是的话,一些例子会很好!
I want to use some kind of trigger to change a button in my window to IsEnabled = False
when the textbox property Validation.HasErrors
of my textbox is True
.
Can I do this with Triggers of some kind on the Button?
If yes, some example would be nice!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以使用触发器来执行此操作,但因为您引用的是另一个元素,所以您必须使用 DataTrigger 而不是普通触发器:
请注意,您必须使用 Style 而不是 Button.Triggers 集合,因为 Button.Triggers 只能包含事件触发器。
Yes, you can do this with triggers, but because you are referring to another element, you must use a DataTrigger rather than a normal Trigger:
Note you must use a Style rather than the Button.Triggers collection, because Button.Triggers can contain only EventTriggers.
您可以使用样式来做到这一点。如果您想将其直接绑定到文本框,您可以执行以下操作:
如果按钮尚未绑定到其他属性的 DataContext,则此方法有效。在这种情况下,样式可重复用于其他按钮和文本框配对。
You can do this by using a Style. If you want to tie it directly to the text box, you could do something like this:
This works if the button is not already binding to the DataContext for other properties. In this case, the Style is reusable for other button and text box pairings.