简体   繁体   中英

WPF checkbox IsChecked binding not working

I have this problem, that my checkbox IsChecked property binding is not working. I googled, but people say it shoudl TwoWay binding which is what I am using.

Here is my code:

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

Here is the C# code behind it:

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

Any pointers are highly appreciated,

This is because you are binding to an array. Pull the property out that you want to bind to a separate property.

Xaml:

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

Code:

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

Try this:

OnPropertyChanged("Item[]"); 

The property generated by the compiler when using an indexer. See this blog post .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM