123*_*per 1 wpf binding itemtemplate icommand
让我用伪代码问这个问题:
__PRE__
其中
"Contacts"将ViewModel对象设置为窗口的DataContext.
"Contacts"具有"PersonCollection",公共ICommand PersonSelectedCommand属性."PersonCollection"是List
"Person"具有Name,Age属性
目前这不起作用,因为CheckBox试图找到并绑定对象"person"的ICommand"PersonSelectedCommand"属性,该属性不存在!
如何将CheckBox绑定到对象"Contact"的ICommand"PersonSelectedCommand"属性
谢谢并问候
123Deveopler
我喜欢SeeSharp的答案,但是要直接回答你的问题,你需要做的就是将CheckBox的Command绑定更改为:
Command="{Binding DataContext.PersonSelectedCommand,
RelativeSource={RelativeSource FindAncestor,ListView,1}}"
Run Code Online (Sandbox Code Playgroud)
只有当您需要更多控制而不是简单地绑定IsSelected属性时,这比SeeSharp的答案更可取.否则选择绑定IsSelected.