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.
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
精彩评论