2012-03-29 6 views
0

私のListBoxItemのスタイルでMouseBindingsを使用しています。ListBoxItem stealing ListBoxからのマウスクリック

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

具体的には、LeftClickコマンドを使用して、ビューモデルでコマンドを起動しています。問題は、マウスイベントがリストボックスに表示されないため、アイテムがListBoxで選択されていないことです。だから、親コントロール(ListBox)にイベントを渡す方法はありますか?

SelectionChangedのListBoxで対話トリガーを使用すると、この問題が発生することがありますが、問題が既に選択されている項目を再度クリックしても名前が示すようにイベントが発生しません。私のリストに問題がある項目が1つしかないとき。

<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

+0

参照する必要があると思うと思います。 –

答えて

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> 
関連する問題