Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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,

like image 612
Nick X Tsui Avatar asked Oct 18 '13 21:10

Nick X Tsui


2 Answers

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");
    }
}
like image 169
Shawn Kendrot Avatar answered Sep 30 '22 01:09

Shawn Kendrot


Try this:

OnPropertyChanged("Item[]"); 

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

like image 33
JBrooks Avatar answered Sep 30 '22 01:09

JBrooks