Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

binding

wpf

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

like image 320
Tony Trembath-Drake Avatar asked Feb 26 '09 12:02

Tony Trembath-Drake


1 Answers

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;
like image 186
Razzie Avatar answered Nov 04 '22 14:11

Razzie