MenuItem.IsEnabled绑定在公共bool上

时间:2012-09-22 04:59:58

标签: c# wpf binding properties

我的WPF App中有MenuItem:

<MenuItem Header="_Login" Click="Login_Click" Name="mi_Login">

如何动态绑定本地bool var上的IsEnabled属性:

public bool _IsConnected
    {
        get { return this.IsConnected; }
        set { this.IsConnected = value; }
    }

1 个答案:

答案 0 :(得分:1)

不要忘记在主容器上设置DataContext:

<Window DataContext="{Binding Path=YourViewModelOrCodeBehindOtherwise}">    
    <MenuItem Header="_Login" Click="Login_Click" Name="mi_Login" 
        IsEnabled="{Binding _IsConnected}" >  
</Window>