0

I'm using Microsoft.Toolkit.MVVM, in doc we can use binding Button command like:

<Button Content="Click me!" Command="{Binding ButtonClickCommand}"/> 

But for ListView, I have to write like with Behaviors, this code is to long:

<ListView> <i:Interaction.Triggers> <i:EventTrigger EventName="SelectionChanged"> <i:InvokeCommandAction Command="{Binding SelectionChangedCommand}" PassEventArgsToCommand="True"/> </i:EventTrigger> </i:Interaction.Triggers> </ListView> 

So why can't use below code instead? This is simple, but not working.

<ListView SelectionChanged={Binding SelectionChangedCommand}/> 
1
  • 1
    They are different types. Command property is of ICommand type, but the SelectionChanged property should be matched with an Event Handler. Commented Jan 13, 2022 at 7:35

1 Answer 1

2

the simple answer is the type of the object in button Command is ICommand and in the ListView the SelectionChanged is an event and not ICommand , this why you need to use eventTrigger which is an "addon"

if you look at it from MVVM perspective the button is here to bind a command the ListView has SelectedItems collection that you can bind to and not the event , but that's more of a choice you need to make (I think that your code looks fine once you are used to it)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.