Jason D
Jason D

Reputation: 2664

Use MenuItem Value as CommandParameter

I have the following MenuItem which comes from a Menu (not a ContextMenu):

<MenuItem DisplayMemberPath="Name"
          Header="Teams"
          ItemsSource="{Binding Teams,
                                Source={StaticResource Container}}">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
            <cmd:EventToCommand Command="{Binding OpenTeamPage}"
                                CommandParameter="{Binding ???}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</MenuItem>

How can I pass the selected item (a Team from the ItemsSource) as a CommandParameter to my Viewmodel? I've done some research but I can't find a way to get the selected item in this situation. Any help would be appreciated.

Upvotes: 1

Views: 939

Answers (1)

Nitin Purohit
Nitin Purohit

Reputation: 18580

If you want to send the clicked menuitem context then

<MenuItem DisplayMemberPath="Name"
          Header="Teams"
          ItemsSource="{Binding Teams,
                                Source={StaticResource Container}}">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
            <cmd:EventToCommand Command="{Binding OpenTeamPage}"
                                PassEventArgsToCommand="True"
        </i:EventTrigger>
    </i:Interaction.Triggers>
</MenuItem>

Upvotes: 1

Related Questions