C# – WPF checkbox IsChecked binding not working

bindingccheckboxwpfxaml

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,

Best Answer

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