これは、リスト内のクリックされた項目に基づいて (ViewModel 内で) コマンドをトリガーするメソッドの実例です。ViewModel のコマンドは、「クリックされた」項目をパラメーターとして取得します。
私は Textblock.InputBindings を使用しています。これは Blachshma によってリンクされたBlend SDKの一部である可能性がありますが、これを機能させるために他の DLL は必要ありません。
私の例では、ViewModel は UserControl の DataContext にバインドされているため、RelativeSource FindAncestorを使用して TextBlock から ViewModel を見つける必要があります。
編集: TextBlockのWidthをListBoxのActualWidthにバインドして、幅の問題を修正しました。
1 つだけ問題があります。ダブルクリックは、リスト自体がはるかに広い場合でも、テキストブロック内のテキスト内をクリックした場合にのみ機能します。
<ListView ItemsSource="{Binding Model.TablesView}" Grid.Row="1"
SelectedItem="{Binding Model.SelectedTable, Mode=TwoWay}" >
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=.}"
Width="{Binding Path=ActualWidth,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}}" >
<TextBlock.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick" Command="{Binding DataContext.MoveItemRightCommand,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type UserControl}}}"
CommandParameter="{Binding .}"/>
</TextBlock.InputBindings>
</TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>