✅ how can i bind command to listboxitem's mousedoubleclick event in a datatemplate

i have this code
<ListBox ItemsSource="{Binding Items}">
<ListBox.ItemTemplate>
<TextBlock Text="{Binding Name}" />
</ListBox.ItemTemplate>
</ListBox>
<ListBox ItemsSource="{Binding Items}">
<ListBox.ItemTemplate>
<TextBlock Text="{Binding Name}" />
</ListBox.ItemTemplate>
</ListBox>
4 Replies
ricecracker2234
ricecracker2234OP2y ago
a
JakenVeina
JakenVeina2y ago
if you need to access the ListBoxItem directly for whatever reason, you need ListBox.ItemContainerStyle or ListBox.ItemContainerTemplate for this, just accessing the TextBlock should be fine and you need the Xaml Behaviors library
<b:Interaction.Triggers>
<b:EventTrigger Event="DoubleClick">
<b:InvokeCommandAction Command="{Binding MyCommand, Mode=OneTime}" />
</b:EventTrigger>
</b:Interaction.Triggers>
<b:Interaction.Triggers>
<b:EventTrigger Event="DoubleClick">
<b:InvokeCommandAction Command="{Binding MyCommand, Mode=OneTime}" />
</b:EventTrigger>
</b:Interaction.Triggers>
assuming "DoubleClick" is an event that exists and that your command doesn't have CanExecute logic actually, now I can't remember for sure if InvokeCommandAction will do a CanExecute check or not point being, if the behavior of any of the above doesn't work for you, you'll have to subclass and implement your own TriggerBase<T>, TriggerAction<T>, or Behavior<T> all of which are quite straightforward or just do it all in codebehind
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
ricecracker2234
ricecracker2234OP2y ago
alrigjt thank you
Want results from more Discord servers?
Add your server