TwoWay 或 OneWayToSource 绑定不能在只读属性上工作 [英] A TwoWay or OneWayToSource binding cannot work on the read-only property

查看:27
本文介绍了TwoWay 或 OneWayToSource 绑定不能在只读属性上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个只读属性,需要在文本框中显示,但在运行时出现此错误.我已经设置了 IsEnabled="False", IsReadOnly="True" - 没有运气.其他搜索说 readonly 应该修复它,但不适合我.我通过添加一个虚拟二传手有一个丑陋的解决方法......

I've a read only property I need to display in a textbox, and getting this error at runtime. I've set IsEnabled="False", IsReadOnly="True" - no luck. Other searches say the readonly should fix it, but not for me. I've got an ugly workaround by adding a dummy setter...

推荐答案

没有代码很难猜,但你应该能够将 BindingMode 设置为 OneWay.

It's hard to guess without code, but you should be able to set the BindingMode to OneWay.

<TextBox Text="{Binding Path=MyProperty, Mode=OneWay}" />

或来自代码:

Binding binding = new Binding();
binding.Mode = BindingMode.OneWay;

这篇关于TwoWay 或 OneWayToSource 绑定不能在只读属性上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆