InvalidOperationException - TwoWay或OneWayToSource绑定在只读属性上无法工作 [英] InvalidOperationException - A TwoWay or OneWayToSource binding cannot work on the read-only property

查看:1188
本文介绍了InvalidOperationException - TwoWay或OneWayToSource绑定在只读属性上无法工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MVVM模式,当我运行我的应用程序时收到以下内容。

I'm using the MVVM pattern and am receiving the following when i run my app

InvalidOperationException
TwoWay或OneWayToSource绑定无法在读 - 只有ViewModel.SynergyViewModel类型的属性选项。

InvalidOperationException A TwoWay or OneWayToSource binding cannot work on the read-only property 'Options' of type 'ViewModel.SynergyViewModel'.

我已经在我的视图模型中注释了我的所有资源,并将其追溯到一个复选框。如果我注释了我的视图模型中的复选框或适当性,应用程序运行,减去功能。下面我列出了我的复选框和viewmodel中的属性的代码。

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 TwoWay或OneWayToSource绑定无法在ViewModel.MyViewModel类型的只读属性选项上工作。
Source = PresentationFramework
StackTrace:
at MS.Internal.Data.PropertyPathWorker.CheckReadOnly(Object item,Object info)
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?

推荐答案

明确设置 绑定。模式 OneWay

这篇关于InvalidOperationException - TwoWay或OneWayToSource绑定在只读属性上无法工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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