Get WPF ContextMenu to show on Winforms NotifyIcon

2019-08-06 13:29发布

问题:

I am using the Winforms NotifyIcon as there is no WPF Version, I am also using the ContextMenu tutorial here: http://www.wpftutorial.net/ContextMenu.html

And I will be using the mouse placement code found in the answer here: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/8cdd4ef1-d31e-42ef-a30e-7b482c0fa163/

My main problem is, the method:

private void OpenContextMenu(FrameworkElement element)
{
    if( element.ContextMenu != null )
    {
       element.ContextMenu.PlacementTarget = element;
       element.ContextMenu.IsOpen = true;
    }
}

How is it used? Can anyone tell me what steps I will need to do just to get this to show up for my NotifyIcon

Thanks

回答1:

CodePlex has a WPF version of NotifyIcon. That might meet your needs better.



回答2:

I found this one out myself, it does the job and very easy to implement.

http://weblogs.asp.net/marianor/archive/2007/10/15/a-wpf-wrapper-around-windows-form-notifyicon.aspx