in one of my apps I have a code like this:
<ProgressBar Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" Height="27" Margin="5,0,5,0" Maximum="{Binding TabuProgressEnd}" Value="{Binding TabuProgress}" />
While I was testing this everything is ok, but when my client opened this under VS and run this code threw an exception:
An unhandled exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll
Additional information: A TwoWay or OneWayToSource binding cannot work on the read-only property 'TabuProgress' of type 'TSPLib.TabuEngine'.
Usually I would think this is some kind of hoax, but I know that the guy has no idea about coding and making the "Mode=OneWay" explicit helped. How is it possible that the default binding mode differs on different machines?
TwoWay: The target property will listen to the source property being changed and will update itself. AND The source property will listen to the target property being changed and will update itself.
In two way binding, source control updates the target control as well as the target control also updates the source control. That means if you change the value of the source control, it will update the value of the target control and if you change value of target control, it changes the value of the source control.
The binding mode defines how the data sources are bound. The different model implementations require specific binding modes. The resource model, for example, only supports one-time binding, that is, a binding from the model to the view.
There three binding modes in SAPUI5: One way binding – Data flows from model to control. Change in the model data updates all the corresponding bindings. Two way binding – Data flows from model to view and view to model.
The Value
property in ProgressBar
binds TwoWay
by default so the exception should occur unless you explicitly set Mode
to OneWay
. However I can't explain why it doesn't occur on your machine. I tried using Reflector with .NET versions 4.0, 3.5 and 3.0 and as far as I can tell, the default binding mode hasn't changed in a while.
If you have Reflector installed, it would be interesting to see what the ValueProperty (inherited from RangeBase) looks like on your machine
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register(
"Value",
typeof(double),
typeof(RangeBase),
new FrameworkPropertyMetadata(
0.0,
FrameworkPropertyMetadataOptions.Journal |
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
new PropertyChangedCallback(RangeBase.OnValueChanged),
new CoerceValueCallback(RangeBase.ConstrainToRange)),
new ValidateValueCallback(RangeBase.IsValidDoubleValue));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With