tags:

views:

404

answers:

1

Hi All,

I have a context menu situated inside a User Control Resource.

<UserControl.Resources>

    <ContextMenu x:Key="Menu1">   

        <MenuItem Header="View/Edit Contact" Command="{Binding SearchCommand}" CommandParameter="editcontact"/>
        <MenuItem Header="View/Edit Company" Command="{Binding SearchCommand}" CommandParameter="editprimarycompany"/>         

    </ContextMenu>


</UserControl.Resources>

This resource is bound to a WPF grid.

Now, after the grid is filled with data, I am right clicking on the grid. And I am able to find the context menu.

The problem is how can I know at runtime which menu item has been clicked?

I have tried with this

var t = this.TryFindResource("Menu1") as Style; in the grid's SelectedItemsChanged event but it is null.

Please help me and also tell me in which event of grid should I will be able to acess this!

Thanks in advance.

I am using C#,WPF,Infragistics Control(WPF)

+2  A: 

Well first of all, why would you cast the Menu1 ContextMenu as a Style? That will always return null because Menu1 is not a Style. Cast it as a ContextMenu.

Secondly, it appears you already have everything in place to determine which menu item has been clicked. You have passed a unique string in the CommandParameter, which you can check at run-time.

Charlie
unique string in the CommandParameter, which you can check at run-time..How and in which event?
priyanka.sarkar
In the CanExecute and Executed events, the event arguments include the CommandParameter. Check e.Parameter.
Charlie