C# WPF 复选框 IsChecked 绑定不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19459615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF checkbox IsChecked binding not working
提问by Nick X Tsui
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.
我有这个问题,我的复选框 IsChecked 属性绑定不起作用。我用谷歌搜索,但人们说它应该是我正在使用的双向绑定。
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:
这是它背后的 C# 代码:
public bool[] LSMChannelEnable
{
get
{
return this._liveImage.LSMChannelEnable;
}
set
{
this._liveImage.LSMChannelEnable = value;
OnPropertyChanged("LSMChannelEnable");
OnPropertyChanged("EnableChannelCount");
OnPropertyChanged("LSMChannel");
}
}
Any pointers are highly appreciated,
任何指针都受到高度赞赏,
采纳答案by Shawn Kendrot
This is because you are binding to an array. Pull the property out that you want to bind to a separate property.
这是因为您绑定到一个数组。拉出要绑定到单独属性的属性。
Xaml:
Xml:
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");
}
}
回答by JBrooks
Try this:
尝试这个:
OnPropertyChanged("Item[]");
The property generated by the compiler when using an indexer. See this blog post.
编译器在使用索引器时生成的属性。请参阅此博客文章。