WPF绑定默认模式 [英] WPF Binding default mode

查看:160
本文介绍了WPF绑定默认模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序之一,我有一个code是这样的:

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}" />

虽然我是测试这一切都很好,但我的客户开了这家VS下时,并运行此code抛出异常:

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?

推荐答案

属性进度结合双向默认情况下,除非你明确地设置应该发生异常模式单向。不过,我无法解释为什么它没有你的机器上出现。我尝试使用反射器采用.NET版本4.0,3.5和3.0,据我所知道的,默认绑定模式一段时间没有改变。

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.

如果您安装了反射,那就看什么ValueProperty(从RangeBase继承)看起来像你的机器上是很有意思

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

这篇关于WPF绑定默认模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆