A TwoWay or OneWayToSource binding cannot work on the read-only property

让人想犯罪 __ 提交于 2019-12-29 11:03:55

问题


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...


回答1:


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}" />

or from code:

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


来源:https://stackoverflow.com/questions/590269/a-twoway-or-onewaytosource-binding-cannot-work-on-the-read-only-property

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!