[英]WPF: Binding to the Binding mode
在WPF中,我尝试使用数据绑定来定义BindingMode。
<controls:BoolToStringConverter x:Key="BoolToStringConverter" FalseValue="OneWay" TrueValue="TwoWay" />
<TextBox Text="{Binding MyText, Mode="{Binding Path=IsWriteable, Converter={StaticResource BoolToStringConverter}}" />
另外,我尝试使用System.Windows.Data.BindingMode枚举作为属性“ MyBindingMode”的数据类型并将其绑定到该列表,但它也不起作用
<TextBox Text="{Binding MyText, Mode={Binding Path=MyBindingMode}}" />
这样的绑定是否有可能,或者有什么合适的方法来实现这一目标?
编辑:
实际上,在我的上下文中,它不是TextBox,而是DataGridTextColumn。 我试图绑定IsReadOnly="{Binding IsOnlyReadable}"
但这对DataGridTextColumn无效。 将其固定设置为IsReadOnly=True
可以,但是将其绑定到一个恒定的true属性不会产生这种效果。
终于解决了,我将它用于绑定DataGridColumn: https : //stackoverflow.com/a/27465022/9758687
看一下这个链接。 这似乎是您正在寻找的内容: .Net v4 DataGridTextColumn.IsReadOnly似乎有问题
这是可能解决您的问题的代码:
<DataGridTextColumn>
<DataGridTextColumn.CellStyle>
<Style>
<Setter Property="UIElement.IsEnabled" Value="{Binding IsOnlyReadable}" />
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.