InvalidOperationException异常 - 一个双向或者OneWayToSource结合不能在只读属性工作 [英] InvalidOperationException - A TwoWay or OneWayToSource binding cannot work on the read-only property
问题描述
我使用的MVVM模式,并收到如下当我运行我的应用程序
I'm using the MVVM pattern and am receiving the following when i run my app
出现InvalidOperationException
一个双向或者OneWayToSource结合不能读取工作 - 只属性类型ViewModel.SynergyViewModel的选项。
InvalidOperationException A TwoWay or OneWayToSource binding cannot work on the read-only property 'Options' of type 'ViewModel.SynergyViewModel'.
我的评论我在我的视图模型的所有源并已追查这回的复选框。如果我注释掉的复选框,或者在我看来,模型中的应用程序运行properity,减去功能。 。下面我列出了我的复选框和视图模型中的属性的代码
I have commented all my source out in my view model and have traced this back to a check box. If i comment out the the checkbox or the properity in my view model the app runs, minus the functionality. Below i have listed the code for my checkbox and the property within the viewmodel.
<CheckBox Grid.Column="4" HorizontalAlignment="Right" Margin="5,0,5,5" IsChecked="{Binding Options}" Content="Options"/>
private bool _Options;
public bool Options
{
get
{
return _Options;
}
private set
{
if (_Options == value)
return;
_Options = value;
OnPropertyChanged("Options");
}
}
System.InvalidOperationException发生
留言= A双向或OneWayToSource结合不能在只读属性选项类型ViewModel.MyViewModel工作。
来源= PresentationFramework
堆栈跟踪:
在MS.Internal.Data.PropertyPathWorker.CheckReadOnly(对象项目,对象信息)
的InnerException:
System.InvalidOperationException occurred Message=A TwoWay or OneWayToSource binding cannot work on the read-only property 'Options' of type 'ViewModel.MyViewModel'. Source=PresentationFramework StackTrace: at MS.Internal.Data.PropertyPathWorker.CheckReadOnly(Object item, Object info) InnerException:
这是什么,我什么,我在这里丢失?
Any ideas on what i'm what i'm missing here?
推荐答案
要么让你的二传手公开任何意见或明确设置 Binding.Mode
以单向
。
Either make your setter public or explicitly set the Binding.Mode
to OneWay
.
这篇关于InvalidOperationException异常 - 一个双向或者OneWayToSource结合不能在只读属性工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!