Capturing selection change / click inside WPF ListView / MVVM

winprofessional 41 Reputation points

Hi, I am trying to get the selection change inside a WPF ListView using Interaction.Triggers. I have only included just the basic XAML for now. But I am getting error in XAML as well as in code.

XAML : The name interaction does not exist in namepace ......interactivity
build: error MC3074: The tag 'Interaction.Triggers' does not exist in XML namespace ''.

Below is the code in XAML


<ListView x:Name="lstItems" Grid.Row="3" FontSize="15"  ItemsSource="{Binding Path=TaskList}" SelectedItem="{Binding Path=SelectedTask}" Foreground="DarkGreen" >
                <i:EventTrigger EventName="MouseLeftButtonUp">
                            Command="{Binding DataContext.SelectItemRelayCommand, 
                                RelativeSource={RelativeSource FindAncestor, 
                                        AncestorType={x:Type ItemsControl}}}"
                            CommandParameter="{Binding Id}">

Could someone please help?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,624 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Lloyd Sheen 1,311 Reputation points

    Since you have bound the SelectedItem I am not sure what you are going to accomplish. This variable will change upon each selection.

    0 comments No comments

  2. DaisyTian-1203 11,611 Reputation points

    You can add Microsoft.Xaml.Behaviors.Wpf in your project Nuget instead of adding dlls in the References

    Step 1 : Right click your project and select Manage Nuget packages.. in the popup window.

    Step 2: Search and install Microsoft.Xaml.Behaviors.Wpf.

    Step 3: Replace xmlns:i="" with xmlns:i=""

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments