【发布时间】:2012-04-13 11:27:30
【问题描述】:
我在 ListBoxItem 的样式中使用 MouseBindings。
<MouseBinding MouseAction="LeftClick" Command="{Binding
DataContext.ViewWorkingImprovementAssetCommand}" CommandParameter="{Binding}"/>
具体来说,我使用 LeftClick 命令在视图模型中触发命令。问题是该项目没有在 ListBox 中被选中,因为鼠标事件没有到达列表框。那么有没有办法将事件传递给父控件(ListBox)?
如果我在 ListBox 上为 SelectionChanged 使用交互触发器,我可以让这个东西工作,但问题是重新单击已选择的项目不会像名称所暗示的那样触发事件。当我的列表中只有一项存在问题时。
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding ViewWorkingImprovementAssetCommand}"
CommandParameter="{Binding ElementName=RemovedImprovementAssetsListBox, Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
有什么想法吗?
【问题讨论】:
-
我认为我们需要查看 Xaml
-
正确回答自己的问题并接受答案,答案不属于问题。
标签: wpf xaml listbox mouseevent listboxitem