wpf - 将 TextBox IsEnabled 绑定(bind)到 VM 的属性

标签 wpf mvvm

这是我的 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/

相关文章:

silverlight - ItemsControl 的内部属性在绑定(bind)到 ItemsSource 时未更新

Android 的 ViewModel 和 MVVM

wpf - 如何使用 MVVM 在 ListView 中设置特定项目?

wpf - 如何在WPF中捕获Ctrl + Tab和Ctrl + Shift + Tab?

WPF XAML 定义的 MenuItem 重用开始工作,然后消失

wpf - 如何在WPF中以均匀间距水平排列控件

c# - 当 child 发生变化时更新 parent

vb.net - 在 Silverlight MVVM 中重新查询 CanExecute 的体面方法?

wpf - 是否可以覆盖 ItemsPresenter 以使用 Virtualizing StackPanel 而不是常规堆栈面板?

c# - 验证规则