我有一个列表视图项,它有一个按钮并显示对象的属性。我使用正确触发的mvvm模式为按钮设置了命令属性。
我的问题是当按下按钮时它也没有获得所选项目,我猜它没有触发selectedItem事件。
按下按钮时是否可以强制执行此事件?
<Button
Height="20"
Width="20"
Grid.Column="3"
Grid.Row="0"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.RemoveClick}"
CommandParameter="{Binding SelectedItem, ElementName=serverListView, Mode=TwoWay}">
答案 0 :(得分:0)
您可以: - 将命令的commandParameter设置为{Binding} - 将SelectedItem绑定到VM的某个属性 - 在命令执行方法
的开头将此属性设置为command参数