WPF 控件之间的依赖关系
我有 3 个文本框,它们的可见性取决于复选框。我想在所有文本框上设置 IsEnabled = false,当 checkbox.IsChecked = false 时设置 IsEnabled = true,当 IsChecked=true 时设置 IsEnabled = true。如何在 XAML 中实现这种依赖关系?
谢谢。
I have 3 textboxes their visibility depends on checkbox. I want to set IsEnabled = false on all textboxes, when checkbox.IsChecked = false and IsEnabled = true when IsChecked=true. How can I achieve this dependency in XAML?
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在命名元素之间进行绑定,并且只要绑定到依赖项属性,绑定就会反映任何更改
you can bind between named elements, and as long as you are binding to dependency properties, the binding will reflect any changes
将
IsEnabled
属性绑定到CheckBox
上的IsChecked
属性。如果您的目标是按照您的问题建议将该 bool 值与
Visibility
联系起来,那么您还需要利用转换器,例如 BooleanToVisibilityConverter。Bind the
IsEnabled
property to theIsChecked
property on theCheckBox
.If your goal is to then tie that bool value to
Visibility
as your question suggests, you would then need to also leverage a converter, such as the BooleanToVisibilityConverter.