加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – WPF复选框IsChecked绑定不起作用

发布时间:2020-12-15 18:19:17 所属栏目:百科 来源:网络整理
导读:我有这个问题,我的复选框IsChecked属性绑定不起作用.我用谷歌搜索,但人们说它shoudl TwoWay绑定,这是我正在使用. 这是我的代码: CheckBox Name="ckC" VerticalAlignment="Center" IsChecked="{Binding Path=LSMChannelEnable[2],Mode=TwoWay,UpdateSourceTr
我有这个问题,我的复选框IsChecked属性绑定不起作用.我用谷歌搜索,但人们说它shoudl TwoWay绑定,这是我正在使用.

这是我的代码:

<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");
    }
}

任何指针都非常感谢,

解决方法

这是因为您绑定到数组.拉出要绑定到单独属性的属性.

XAML:

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

码:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读