MVVM light EventToCommand: get selected item

1.3k Views Asked by At

I have a treeview where I can click on items. I am using MVVM light toolkit and the EventToCommand and would like to know which item was chosen. How can I pass this to my viewmodel?

<interact:Interaction.Triggers>
            <interact:EventTrigger EventName="SelectedItemChanged">
                <cmd:EventToCommand Command="{Binding Path=DataContext.SimpleCommand, RelativeSource={RelativeSource AncestorType={x:Type TreeView}}, Mode=OneWay}" 
                                    CommandParameter="{Binding SelectedItems, ElementName=mainTreeView}"
                                    />
            </interact:EventTrigger>
       </interact:Interaction.Triggers>
1

There are 1 best solutions below

1
On

http://www.galasoft.ch/mvvm/#intro With the newest version, you can get the EventArgs of the fired event directly in the ViewModel to handle it.