문제

I have made a context menu which is activated via MouseDownevent. 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.

도움이 되었습니까?

해결책 2

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top