There is a checkbox in my form, which is bound two-ways to a boolean value in my model. There is a special case, where the user clicks on the checkbox, is presented a question, and may answer “no”. In this case, the action fails, and the checkbox should not be checked.
I have tried with several variations of this, but it won’t work, in the sense that the model is correctly set to false, but the checkbox in the UI gets checked anyway.
private bool _isName = false;
public bool isName {
get { return _isName; }
set {
if (value && specialCase) {
if(user answers no)
value = false;
}
_isName = value;
NotifyPropertyChanged("isName");
}
}
How can I do this?
Create custom
MessageBoxwhich will get as a parameter cancellation command and command which you will invoke in case user input is positive. Then create two additional methods toViewModelwhich will be responsible for changingisNameproperty. InxamladdEventTriggertoCheckBoxon Click event within which show custom MessageBox. Then bind commands that are responsible for changing property to MessageBox.If you need some code samples or more clarification – I’ll provide them.