2012-03-29 52 views
0

我在我的ListBoxItem的样式中使用MouseBindings。ListBoxItem偷鼠标单击列表框

<MouseBinding MouseAction="LeftClick" Command="{Binding  
DataContext.ViewWorkingImprovementAssetCommand}" CommandParameter="{Binding}"/> 

具体来说,我使用LeftClick命令来激发视图模型中的命令。问题是该项目没有在列表框中被选中,因为鼠标事件没有进入列表框。那么有没有办法将事件传递给父控件(ListBox)?

如果我在SelectionChanged的ListBox上使用交互触发器,但可以重新点击已经选择的项目不会像名称所示那样触发事件,我可以让这件事情起作用。而当我的名单只有一个问题的项目。

<i:Interaction.Triggers> 
    <i:EventTrigger EventName="SelectionChanged"> 
     <i:InvokeCommandAction Command="{Binding ViewWorkingImprovementAssetCommand}" 
           CommandParameter="{Binding ElementName=RemovedImprovementAssetsListBox, Path=SelectedItem}" /> 
    </i:EventTrigger> 
</i:Interaction.Triggers> 

任何想法?

+0

我认为,我们需要看到的XAML – Phil 2012-03-29 19:08:07

+0

正确回答自己的问题,接受的答案拍摄,答案并不在问题的归属。 – 2012-04-12 23:07:15

回答

0

显然MouseBinding窃取事件并且不会传递它。我使用我们解决方案中已有的AttachedBehaviors解决了这个问题。我觉得从这个http://marlongrech.wordpress.com/2008/12/13/attachedcommandbehavior-v2-aka-acb/

最终代码解决方案

<cmd:CommandBehaviorCollection.Behaviors> 
<cmd:BehaviorBinding Event="MouseLeftButtonDown" 
        Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl, AncestorLevel=1}, Path=DataContext.ViewWorkingImprovementAssetCommand}" 
        CommandParameter="{Binding}"/> 
</cmd:CommandBehaviorCollection.Behaviors> 
相关问题