【发布时间】:2011-03-04 18:50:55
【问题描述】:
让我用伪代码问这个问题:
<Window>
<ListView ItemsSource="{Binding PersonCollection}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Name}" />
<TextBlock Text="{Binding Path=Age}" />
<TextBlock Text="/" />
<CheckBox Command="{Binding PersonSelectedCommand}" /> <!-- Where "PersonSelectedCommand" is a public command property available in ViewModel object (lets say "Contacts" in this context)-->
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Window>
在哪里
“联系”设置为窗口 DataContext 的 ViewModel 对象。
"Contacts" 具有 "PersonCollection" ,公共 ICommand PersonSelectedCommand 属性。
“PersonCollection”是列表
“人”具有姓名、年龄属性
目前这不起作用,因为 CheckBox 正在尝试查找并绑定对象“person”的 ICommand“PersonSelectedCommand”属性,该属性不存在!
如何将 CheckBox 绑定到对象“Contact”的 ICommand“PersonSelectedCommand”属性
感谢和问候
123开发者
【问题讨论】:
标签: wpf binding itemtemplate icommand