为什么不ListView.InputBindings
work?
我已经实施了Interaction.Triggers
同样的方式,效果很好。
<ListView Name="listView1" ItemsSource="{Binding Cars}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseClick">
<i:InvokeCommandAction Command="{Binding ItemSelectCommand}" CommandParameter="{Binding ElementName=listView1,Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ListView.InputBindings>
<MouseBinding Gesture="LeftClick" Command="{Binding ItemSelectCommand}" CommandParameter="{Binding ElementName=listView1,Path=SelectedItem}"/>
</ListView.InputBindings>
</ListView>
如果它应该在没有(System.Windows.Interactivity
for Interaction.Triggers
)
正如 @Grx70 在对此答案的评论中提到的,LeftClick
父级中定义的鼠标手势ListView
不会为ListViewItem
因为该项目处理此手势以获得焦点,所以它不会使该手势冒泡。
你可以改变你的InputBinding
处理至ListViewItem
itself:
<ListView Name="listView1" ItemsSource="{Binding A}">
<ListView.ItemTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding}">
<ContentPresenter.InputBindings>
<MouseBinding Gesture="LeftClick" Command="{Binding DataContext.ItemSelectCommand, ElementName=listView1}" CommandParameter="{Binding ElementName=listView1,Path=SelectedItem}"/>
</ContentPresenter.InputBindings>
</ContentPresenter>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
您还可以阅读更多有关如何InputBinding
工作于这个问题,有一个答案对此进行了解释。答案建议还创建一种附加行为。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)