Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF绑定默认模式_Wpf_Binding - Fatal编程技术网

WPF绑定默认模式

WPF绑定默认模式,wpf,binding,Wpf,Binding,在我的一个应用程序中,我有如下代码: <ProgressBar Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" Height="27" Margin="5,0,5,0" Maximum="{Binding TabuProgressEnd}" Value="{Binding TabuProgress}" /> 通常我会认为这是一种恶作剧,但我知道这家伙不知道如何编码和使“Mode=OneWay”显式化。不同机器上的

在我的一个应用程序中,我有如下代码:

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

通常我会认为这是一种恶作剧,但我知道这家伙不知道如何编码和使“Mode=OneWay”显式化。不同机器上的默认绑定模式如何可能不同

默认情况下,
ProgressBar
中的
属性绑定
双向
,因此除非您明确将
模式
设置为
单向
,否则应发生异常。但是,我无法解释为什么它不会出现在您的机器上。我试着在.NET版本4.0、3.5和3.0中使用Reflector,据我所知,默认绑定模式已经有一段时间没有改变了

如果您安装了Reflector,那么查看机器上的ValueProperty(继承自RangeBase)是什么样子会很有趣


这听起来像是框架的版本问题。我不确定默认绑定模式是什么时候更改的,但它可能位于某个service Pack(或修补程序)中。这些年来似乎发生了一些奇怪的变化,很难跟踪。您的目标版本是什么?Net Framework 4.0,与Visual Studio 2010一起安装。我不能确定,但这可能是新的东西,因为我的客户端两天前安装了VS Pro试用版。也许是Sp1。谢谢你的回答。首先,我了解到可以在DP元数据中设置默认绑定模式——我以后肯定会更加小心。我已经在我的框架上检查了上面的代码,默认情况下它也包含了bindstwoway。这很奇怪。。
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'.
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));