c# - My WPF ContextMenu is not dismissing when I click elsewhere -
i have wpf contextmenu instance declared in xaml this <window.contextmenu> <contextmenu> <menuitem header="do nothing"/> <separator/> <menuitem header="{x:static p:resources.menuexit}" click="iconmenu_exit"/> </contextmenu> </window.contextmenu> i'm using winforms notifyicon display tray icon this _notifyicon = new system.windows.forms.notifyicon(); _notifyicon.icon = properties.resources.mainicon; _notifyicon.visible = true; _notifyicon.mouseclick += new system.windows.forms.mouseeventhandler(ontrayiconmouseclick); the implementation of mouse click handler this private void ontrayiconmouseclick(object sender, system.windows.forms.mouseeventargs e) { if (e.button == system.windows.forms.mousebuttons.right) { contextmenu.isopen = true; } } this displays context menu , clicking on menu items dismisses it, if click away on window, context menu