WPF default binding mode

in one of my applications, I have this code:

<ProgressBar Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" Height="27" Margin="5,0,5,0" Maximum="{Binding TabuProgressEnd}" Value="{Binding TabuProgress}" /> 

While I tested everything, everything is in order, but when my client opened it under VS and ran this code, it was excluded:

 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 that this is some kind of hoax, but I know that the guy has no idea about coding and helps "Mode = OneWay" to help clearly. How is it possible that the default binding mode is different on different machines?

+7
source share
1 answer

The Value property in the ProgressBar by default binds TwoWay , so an exception should occur if you do not explicitly set Mode to OneWay . However, I cannot explain why this does not happen on your machine. I tried using Reflector with versions of .NET 4.0, 3.5, and 3.0, and as far as I can tell, the default binding mode did not change after a while.

If you have Reflector installed, it would be interesting to see what ValueProperty (inherited from RangeBase) looks like on your computer.

 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)); 
+4
source

All Articles