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 stays visible. seems strange default behavior. there way display context menu other isopen or have explicitly hide context menu somehow?

edit: don't know if matters window's datacontext set this in code-behind.

edit2: context menu dismisses if it's invoked right clicking on actual main window not tray icon.

check have not defined staysopen property true.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -