简体   繁体   English

升级 .NET 版本后,TwoWay 或 OneWayToSource 绑定无法在只读属性上工作

[英]A TwoWay or OneWayToSource binding cannot work on the read-only property after upgrading the .NET version

I have WPF application with target framework version as 4.5 .我有目标框架版本为4.5 WPF 应用程序。 Now I have switched to version 4.6.2 .现在我已经切换到版本4.6.2

After that, I am getting the following error in multiple places.之后,我在多个地方收到以下错误。

A TwoWay or OneWayToSource binding cannot work on the read-only property 

I am using Visual Studio 2017 .我正在使用Visual Studio 2017

Call the project as A and it has B, C, D as dependencies .将项目称为A ,它有B, C, D as dependencies While B, C, and D are attached as DLL 's I am getting the error.虽然 B、C 和 D as DLL附加as DLL但我收到错误消息。 If they are attached as projects I am not getting the error.如果它们as projects附加as projects我不会收到错误消息。

Note: All B, C, D are 4.5 version projects and I am not changing them into 4.6.2 for running this project.注意:所有 B、C、D 都是 4.5 版本项目,我不会将它们更改为 4.6.2 来运行此项目。

Can anyone update me on how to proceed further here and if there is any mistake in the way of approaching?任何人都可以告诉我如何在此处进一步进行以及在接近的方式上是否有任何错误?

Update 1:更新 1:

The related question is different from my case:相关问题与我的情况不同:

A TwoWay or OneWayToSource binding cannot work on the read-only property TwoWay 或 OneWayToSource 绑定不能在只读属性上工作

Update 2:更新 2:

The following question is similar.下面的问题类似。

A TwoWay or OneWayToSource binding cannot work on the read-only property . TwoWay 或 OneWayToSource 绑定不能在只读属性上工作

but the link provided in the answer seems to be broken or redirected:但答案中提供的链接似乎已损坏或重定向:

https://connect.microsoft.com/VisualStudio/feedback/details/773682/wpf-property-with-private-setter-is-updated-by-a-twoway-binding https://connect.microsoft.com/VisualStudio/feedback/details/773682/wpf-property-with-private-setter-is-updated-by-a-twoway-binding

I know it's year late, but if anyone runs into this, it's known problem.我知道已经晚了一年,但如果有人遇到这个问题,那就是已知问题。 After framework upgrade, parts of my UI started throwing InvalidOperationException.框架升级后,我的部分 UI 开始抛出 InvalidOperationException。 The fix was easy, just add explicit Mode=OneWay to the binding.修复很简单,只需在绑定中添加显式 Mode=OneWay 即可。 But I still needed to know why it started if nobody changed anything in code for quite some time.但是我仍然需要知道如果在很长一段时间内没有人更改代码中的任何内容,它为什么会开始。

I found the solution here: https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/retargeting/4.5-4.6.1#two-way-data-binding-to-a-property-with-a-non-public-setter-is-not-supported我在这里找到了解决方案: https : //docs.microsoft.com/en-us/dotnet/framework/migration-guide/retargeting/4.5-4.6.1#two-way-data-binding-to-a-property- with-a-non-public-setter-is-not-supported

Attempting to data bind to a property without a public setter has never been a supported scenario.尝试将数据绑定到没有公共 setter 的属性从来不是一种受支持的场景。 Beginning in the .NET Framework 4.5.1, this scenario will throw an InvalidOperationException.从 .NET Framework 4.5.1 开始,这种情况将引发 InvalidOperationException。 Note that this new exception will only be thrown for apps that specifically target the .NET Framework 4.5.1.请注意,此新异常只会针对专门针对 .NET Framework 4.5.1 的应用程序引发。 If an app targets the .NET Framework 4.5, the call will be allowed.如果应用面向 .NET Framework 4.5,则将允许调用。 If the app does not target a particular .NET Framework version, the binding will be treated as one-way.如果应用程序不面向特定的 .NET Framework 版本,则绑定将被视为单向。

The problem was always there, it only just started throwing exception when it happens.问题一直存在,它只是在发生异常时才开始抛出异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 InvalidOperationException - TwoWay 或 OneWayToSource 绑定无法在只读属性上工作 - InvalidOperationException - A TwoWay or OneWayToSource binding cannot work on the read-only property wpf datagrid单元格编辑错误:( TwoWay或OneWayToSource绑定不适用于只读属性) - wpf datagrid cell edit error : ( A TwoWay or OneWayToSource binding cannot work on the read-only property) 在自定义控件上进行OneWayToSource / TwoWay绑定 - Making a OneWayToSource/TwoWay binding on custom control DataTemplate 中只读属性的绑定更新 - Binding Update of a Read-Only Property in DataTemplate ListBoxItem和ListBoxContainer之间的IsSelected属性的TwoWay绑定导致意外行为。 OneWayToSource工作。 为什么? - TwoWay binding of IsSelected property between ListBoxItem and ListBoxContainer causes unexpected behaviour. OneWayToSource works. Why? 二维TwoWay绑定可以用作OneTime + OneWayToSource - 2-dimension TwoWay binding works as OneTime+OneWayToSource 将ComboBox TwoWay绑定到属性 - Binding ComboBox TwoWay to Property 只读依赖属性更新但在第一次使用时不起作用 - Read-only Dependency Property updates but does not work on first use Azure AD:属性“ mail”是只读的,无法设置 - Azure AD: Property 'mail' is read-only and cannot be set 为什么 .net 的 MailMessage class 的 To 属性是只读的? - Why is the To property of .net's MailMessage class read-only?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM