c# - WPF 复选框 IsChecked 绑定(bind)不起作用

标签 c# wpf xaml checkbox binding

我有这个问题,我的复选框 IsChecked 属性绑定(bind)不起作用。我用谷歌搜索,但人们说它应该是我正在使用的 TwoWay 绑定(bind)。

这是我的代码:

 <CheckBox Name="ckC" VerticalAlignment="Center"
           IsChecked="{Binding Path=LSMChannelEnable[2],
                               Mode=TwoWay,
                               UpdateSourceTrigger=PropertyChanged}" />

这是其背后的 C# 代码:

public bool[] LSMChannelEnable
{
    get
    {
        return this._liveImage.LSMChannelEnable;
    }
    set
    {
        this._liveImage.LSMChannelEnable = value;
        OnPropertyChanged("LSMChannelEnable");
        OnPropertyChanged("EnableChannelCount");
        OnPropertyChanged("LSMChannel");
    }
}

非常感谢任何指点,

最佳答案

这是因为您绑定(bind)到一个数组。将要绑定(bind)到单独属性的属性拉出。

Xaml:

IsChecked="{Binding Path=ButtonEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 

代码:

public bool ButtonEnabled
{
    get { return this._liveImage.LSMChannelEnable[2]; }
    set { this._liveImage.LSMChannelEnable[2] = value;
         OnPropertyChanged("ButtonEnabled");
    }
}

关于c# - WPF 复选框 IsChecked 绑定(bind)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19459615/

相关文章:

Windows 通用 (UWP) 图表库

c# - 带有 ASP.Net MVC RouteConfig 的 AngularJS Ui-Router。它是如何工作的?

c# - 有没有办法静默安装 vb6 或 .NET(最好是 C#)应用程序?

c# - 缓存键导致错误 "Negating the minimum value of a twos complement number is invalid."

c# - C++ AMP计算与WPF渲染显卡双用性能

wpf - 按钮可见性绑定(bind)不更新

wpf - FontSize 未在 Contentpresenter 和 ContentControl 中继承的解决方法

c# - 十进制不能做什么,但双倍可以,反之亦然?

从空闲状态返回时,WPF应用程序变慢

c# - WPF 数据网格分页