开发者

Checkbox in silverlight + viewmodel + C#

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜