这是我的 View 中经过清理的控件层次结构及其绑定(bind)(我希望 SO 不会删除前导空格!!!)...
用户控制
堆栈面板
ListView ItemsSource="{Binding LineItems}"SelectedItem="{Binding SelectedLineItem}"
GridView
GridViewColumn
GridViewColumn.CellTemplate
数据模板
TextBox Text="{绑定(bind)说明}"
LineItems 和 SelectedLineItem 是我的 ViewModel 中的属性,而Description 是SelectedLineItem 引用的类中的一个属性。
现在我需要根据我的 ViewModel 中的新“AllowEdit”属性启用/禁用 TextBox(AllowEdit 不是 SelectedLineItem 的属性)。
如何将 TextBox 的 IsEnabled 属性绑定(bind)到 AllowEdit 属性?
我已经完成了必要的阅读,但不清楚如何做到这一点!
谢谢!
爸爸猫
最佳答案
<TextBox IsEnabled="{Binding DataContext.AllowEdit, RelativeSource={RelativeSource AncestorType=ListView}}"/>
关于wpf - 将 TextBox IsEnabled 绑定(bind)到 VM 的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18795817/