我有一个列表,它通过绑定到它的VMki 属性来接收元素:
<ItemsControl ItemsSource="{Binding Items}">
<ItemsControl.ItemsTemplate>
<DataTemplate>
<Button Content="Удалить" Command="{Binding ElementName=Parent, Path=DataContext.DeleteItem" CommandParameter="{Binding Id}"/>
</DataTemplate>
</ItemsControl.ItemsTemplate>
</ItemsControl>
这里有一个按钮:
<Button Content="Удалить" Command="{Binding ElementName=Parent, Path=DataContext.DeleteItem" CommandParameter="{Binding Id}"/>
为了使命令正常工作,我需要传递Item.Id并且已经在命令代码中,我需要通过按 Id 搜索匹配来查找具有此索引的元素。不舒服。
是否有可能以某种方式将对象本身传递给命令Item,而不是它的属性Id?
您只需要不写属性名称: