Reputation: 12424
I have made a context menu which is activated via MouseDown
event. This event checks if the user clicked the right button and if so opens the menu. I am using the same event to open the same context menu for a listbox and a listview. Is there a way to check which one of them activated the MouseDown event?
Edit: I'll be a bit more specific. I can tell which controller activated the event from the event itself.. I want to know which controller activated the event from the context menu item which has been clicked on.
Upvotes: 2
Views: 289
Reputation: 12424
I solved it by using the Tag property of the context menu. I put there the sender object which triggered the event, and then I could just do:
ListView lv = resultsContextMenu.Tag as ListView;
if (lv == null) //listbox was the one to call the mouse down event
{ //do stuff }
this code was called inside the menu items themselves that were chosen by the user
Upvotes: 0
Reputation: 1091
If you have something like that:
private void MouseDown(object sender, MouseButtonEventArgs e)
{
}
you can check sender
:
if(sender is ListView)
{
//event fired by ListView
}
if(sender is ListBox)
{
//event fired by ListBox
}
etc.
Upvotes: 2