开发者

Checkbox in silverlight + viewmodel + C#

开发者 https://www.devze.com 2023-03-16 00:45 出处:网络
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 simp

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
0

精彩评论

暂无评论...
验证码 换一张
取 消