Capturing selection change / click inside WPF ListView / MVVM

winprofessional 41 Reputation points
2020-09-20T12:25:43.187+00:00

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 'http://schemas.microsoft.com/expression/2010/interactivity'.

Below is the code in XAML

 xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
....
...


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

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,697 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Lloyd Sheen 1,401 Reputation points
    2020-09-20T19:19:12.49+00:00

    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,616 Reputation points
    2020-09-21T03:09:12.147+00:00

    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.
    26007-image.png

    Step 3: Replace xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" with xmlns:i="http://schemas.microsoft.com/xaml/behaviors"


    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