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...
A TwoWay or OneWayToSource binding cannot work on the read-only property
If you do want two way binding, the property setter must be public. See #8773650 –
Girdle
And from the department of the blindingly obvious, the setter must also exist; i.e. a property with just a get will exhibit the same issue. –
Clarissaclarisse
@ColonelPanic "I've a read only property I need to display in a textbox" tells me that the asker isn't trying to do a two-way binding. I think he hadn't specified the binding mode and so it defaulted to TwoWay. –
Longboat
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;
Yep, "Mode=OneWay" == Read Only; "Mode=OneWayToSource" == Write Only –
Jobholder
Please note that in .NET 4.0 there's a "bug" that OneWayToSource also does a get: #14968167 –
Krohn
Also, for TwoWay Binding on Settings see https://mcmap.net/q/182211/-bind-to-a-value-defined-in-the-settings –
Publicspirited
This together with #871393 solved my problem. Thanks! One thing remains unclear: Why does my app run fine within Visual Studio despite this issue? –
Longboat
© 2022 - 2024 — McMap. All rights reserved.