c# - MenuItem.IsEnabled 绑定(bind)到公共(public) bool 值

标签 c# wpf binding properties

我的 WPF 应用程序中有 MenuItem:

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

如何在我的本地 bool var 上动态绑定(bind) IsEnabled 属性:

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

?

最佳答案

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

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

关于c# - MenuItem.IsEnabled 绑定(bind)到公共(public) bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12540849/

相关文章:

c# - 用于在 System.Label 上准确放置文本的图形 DrawString

c# - XAML ListBox 只显示类名

c# - SQLite:创建表并在表不存在时添加一行

c# - 通过部分填充属性定位元素 Selenium/C#

c# - 获取命令绑定(bind)上的点击位置

python - Tkinter (Python 3.x) 中的不同 "Drag and Drop"图像

wpf - 如何通过仅单击用户控件中的一个按钮来更新框架的 Source 属性?

spring - 在 Spring Security SAML 身份验证请求中配置 POST ProtocolBinding

c# - 如何在要打印的收据上添加选定的 ListBox 项目及其价格?

.net - 用户界面允许 700 多种选择