开发者

WPF Binding default mode

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.InvalidOperationExcept开发者_运维问答ion' 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?


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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜