2012-03-29 35 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> 
相關問題