Reputation: 5
I have two checkboxes A and B. I want B to be disabled when I check A. Do you know how to do it? Thank you in advance.
Upvotes: 0
Views: 437
Reputation: 30097
Well if you are using MVVM
as it seems from viewmodel
tag then simply create a bool
property in view model
and bind checkbox A's
IsChecked
with this property.
XAML
Checkbox IsChecked= {Binding path = IsACheckedProperty ...} //A
.CS
public bool IsACheckedProperty
{
get
{
return associated var;
}
set
{
var = val;
if(var)
IsBEnabled = false;
else
IsBEnabled = true;
}
}
Now create another property IsBEnabled for disabling B once A is checked.
public bool IsBEnabled
{
get
{
return associated var;
}
set
{
var = val;
//notify view via notifyPropertyChanged
}
}
XAML
Checkbox IsEnabled = {Binding path = IsBEnabled...} //B
Upvotes: 1