2

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.

4

2 に答える 2

2

そのようなものがある場合:

private void MouseDown(object sender, MouseButtonEventArgs e)
{

}

あなたがチェックすることができますsender:

if(sender is ListView)
{
    //event fired by ListView
} 

if(sender is ListBox)
{
    //event fired by ListBox
} 

于 2013-05-25T14:55:35.350 に答える
0

コンテキストメニューのTagプロパティを使って解決しました。イベントをトリガーした送信者オブジェクトをそこに配置すると、次のことができます。

ListView lv = resultsContextMenu.Tag as ListView;
if (lv == null) //listbox was the one to call the mouse down event
{ //do stuff }

このコードは、ユーザーが選択したメニュー項目自体の中で呼び出されました

于 2013-05-25T18:06:35.833 に答える