Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
674 views
in Technique[技术] by (71.8m points)

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

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

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

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 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Either make your setter public or explicitly set the Binding.Mode to OneWay.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...