在我的一个应用程序中,我有一个这样的代码:
<ProgressBar Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" Height="27" Margin="5,0,5,0" Maximum="{Binding TabuProgressEnd}" Value="{Binding TabuProgress}" />
Run Code Online (Sandbox Code Playgroud)
虽然我在测试这一切都没问题,但是当我的客户端在VS下打开它并运行此代码时抛出异常:
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'.
Run Code Online (Sandbox Code Playgroud)
通常我会认为这是某种骗局,但我知道这个家伙不知道编码并使"Mode = OneWay"明确有帮助.不同机器上的默认绑定模式有何不同?
Value默认情况下, 中 的属性会绑定ProgressBar,因此除非您显式设置为TwoWay,否则应该会发生异常。但是我无法解释为什么它不会出现在你的机器上。我尝试将 Reflector 与 .NET 版本 4.0、3.5 和 3.0 一起使用,据我所知,默认绑定模式有一段时间没有改变。ModeOneWay
如果您安装了 Reflector,那么看看 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));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6363 次 |
| 最近记录: |