WPF .NET 4中 - OneWayToSource结合只写属性适用于某些机器!怎么样? [英] WPF .Net 4 - OneWayToSource binding to write-only property works on some machines! How?

查看:105
本文介绍了WPF .NET 4中 - OneWayToSource结合只写属性适用于某些机器!怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近增加了一个OneWayToSource在我们的code在一个视图模型绑定到一个只读属性。当时我不知道是.NET 4的变化,即当没有消气,这将导致异常:

I recently added a OneWayToSource binding in our code to a read-only property in a view model. At the time I did not know about the change in .Net 4, that this will cause an exception when there is no getter:

<Popup IsOpen="{Binding IsPopupOpen, Mode=OneWayToSource}" />
...
public bool IsPopupOpen
{
    set
    {
        // do something with value
    }
}

现在的问题是,这个code 工作我的电脑上没有抛出异常。完全相同的可执行文件并不在其他机器上工作 - 在弹出不开的,预期的异常被抛出。我想不通这是怎么可能呢?该项目面向.NET FW 4。

The problem is, this code works on my computer without throwing an exception. The exact same executable does not work on other machines - the popup does not open, and the expected exception gets thrown. I cannot figure out how this is possible? The project targets .Net FW 4.

我做了一定要清除我的bin文件夹和重建,但它仍然是工作无一例外我的机器上,而不是其他人。

I made sure to clear out my bin folder and rebuild, but it is still working without exception on my machine, and not on others.

我知道如何修理这个 - 只需添加一个getter的财产。不过,我需要弄清楚如何将程序在不同的机器上运行不同的,因为这可能导致其他严重的问题...

I know how to "fix" this - simply add a getter to the property. However I need to figure out how the program is functioning differently on different machines, as this could cause other serious issues...

编辑:

这是推动我疯了!我看用史努比WPF工具我弹出,并有似乎没有在所有结合ISOPEN(的结合是一个新的除了XAML)。不过,如果我将调试器附加到应用程序,并设置绑定属性的setter方法​​中设置断点,它击中我的断点!!

This is driving me mad! I look at my popup using Snoop WPF utility, and there appears to be no binding to IsOpen at all (the binding is a new addition to the XAML). However, if I attach the debugger to the app and set a breakpoint inside the setter of the bound property, it hits my breakpoint!!

推荐答案

猜测的一点。

有合理的,这一变化在净4.0后,他们决定把它在.NET 4.5更加一致:如果吸气存在属性重读回到UI,否则没有什么可怕的情况发生,并不会引发任何异常

There's plausible that after this change in net 4.0 they decided to make it more consistent in .net 4.5: if getter exists property is reread back to UI, otherwise nothing terrible happens and no exception is thrown.

如果这样,你有.NET 4.5安装,你可以得到这样的行为,而不是所预期的。
我们见过面情况下,当更新到4.5传播到4.0悄无声息。

If so and you have .net 4.5 installed you can get this behavior instead of the expected one.
We've met cases when updates to 4.5 propagated to 4.0 silently.

这篇关于WPF .NET 4中 - OneWayToSource结合只写属性适用于某些机器!怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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