There are few problems with your code, namely:
- you're creating way too many
SettingsModel
instances (should have one, living in view model bound to your view) cbxhasAccess_Checked_1
are not needed as you're binding withTwoWay
mode
To fix this, first and foremost you should expose settings model (or IsActive
property) on your view model:
// view model
public SettingsModel Settings { get; private set; }
// view model constructor
Settings = new SettingsModel();
Then in your view your binding changes to:
<CheckBox ... IsChecked="{Binding Settings.IsActive, Mode=TwoWay}" />
Note that cbxhasAccess_Checked_1
method is not needed.
This however (exposing settings model) is not the best idiomatic way to resolve this problem with MVVM. Instead, you could keep SettingsModel
private within view model and wrap around it's IsActive
property:
public bool IsActive
{
get { return settingsModel.IsActive; }
set
{
if (settingsModel.IsActive != value)
{
settingsModel.IsActive
RaisePropertyChanged("IsActive");
}
}
}
Either way, important point is to have only one instance of SettingsModel
within view model.