WPF ListBox には、少なくとも私が知る限り DoubleClick イベントはありません。この問題を回避するには、項目をダブルクリックしてイベント ハンドラーで何かを実行できるようにする方法がありますか? ご協力ありがとうございます。
ベストアンサー1
ListBoxItem
パラメータ付きのコマンドをsにバインドすることは可能です。コードビハインドまたは付随行動InputBindings
、単にMouseBinding
前述のようにこの答え。
forListBox
の例:MouseBinding
LeftDoubleClick
<ListBox ItemsSource="{Binding MyDataSource}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding MySourceItemName}">
<TextBlock.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick"
Command="{Binding DataContext.MyCommand, RelativeSource={RelativeSource AncestorType={x:Type ListBox}}}"
CommandParameter="{Binding MySourceItemId}" />
</TextBlock.InputBindings>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
ItemsSource
コマンドがのと同じ DataContext で定義されている場合は、例に含まれているバインディングをListBox
使用してバインドできます。RelativeSource