Reputation: 1061
I am having some problems finding the correct property to use to bind a click event on a ListBoxItem to a property in my ViewModel.
Here is my ListBox XAML code:
<ListBox dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True" Background="#ececec" SelectedItem="{Binding SelectedSlideDataItem}" ItemsSource="{Binding SlideDataItems}" Grid.Column="2" Grid.Row="10" Grid.RowSpan="4" Grid.ColumnSpan="13">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<!--<Setter Property="Padding" Value="5,0,5,5" />-->
<Setter Property="Height" Value="110"/>
<Setter Property="Width" Value="200"/>
<Style.Triggers>
<Trigger Property="Control.IsMouseOver" Value="True">
<Setter Property="ToolTip">
<Setter.Value>
<Image Source="{Binding BackgroundImage}" Height="240" Width="400" />
</Setter.Value>
</Setter>
<Setter Property="Control.Background" Value="#d64b36" />
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#c83a25" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#c83a25" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="#c83a25"/>
</ListBox.Resources>
</ListBox>
So when a user clicks one of the items in the ListBox. I need an event to fire in my ViewModel.
Upvotes: 0
Views: 1531
Reputation:
1) With Interactivity and MVVM :
<ListBox>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction Command="{Binding YourCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
2) - Or in Style without MVVM
<Style TargetType="ListViewItem">
<EventSetter Event="MouseDoubleClick" Handler="ListViewItem_MouseDoubleClick"/>
</Style>
Upvotes: 1
Reputation: 1610
Use MouseLeftButtonUp
event
<ListBox dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True"
Background="#ececec" SelectedItem="{Binding SelectedSlideDataItem}" ItemsSource="
{Binding SlideDataItems}" Grid.Column="2" Grid.Row="10" Grid.RowSpan="4"
Grid.ColumnSpan="13" MouseLeftButtonUp={//Bind with VM}/>
Upvotes: 0