wpf-notifyicon
wpf-notifyicon copied to clipboard
Opening Context Menu instantly closes again
I've created the TaskbarIcon as following (although styles have been added, but the issue remains even when I use an exact copy of this TaskbarIcon.
The issue is that whenever I open the Context Menu (Right click), it'll instantly close after being open for about half a second. I have no idea what causes this issue and messing around with the Focusable property didn't change anything
<tb:TaskbarIcon x:Key="TaskbarIcon"
IconSource="pack://application:,,,/AudioBand;component/audioband.ico"
ToolTipText="AudioBand"
DoubleClickCommand="{Binding OpenSettingsMenuCommand}">
<tb:TaskbarIcon.ContextMenu>
<ContextMenu>
<MenuItem Header="Settings" Command="{Binding OpenSettingsMenuCommand}">
<MenuItem.Icon>
<TextBlock FontFamily="Segoe MDL2 Assets" Text="" />
</MenuItem.Icon>
</MenuItem>
<Separator />
</ContextMenu>
</tb:TaskbarIcon.ContextMenu>
</tb:TaskbarIcon>
A context menu usually closes when there is a change of focus, so the first thing that comes to my mind is that you might want to look if another thing steals the focus?
Yeah I've considered this too but I don't remember setting focus anywhere specifically. I'll check again tomorrow though! Are there any limitations to what can take the focus? Only something TrayIcon related? Or is it possible it happens in my app itself too?
I'm hitting the same issue. Within VS, ShowContextMenu is firing twice, which is probably why it's closing immediately. Once it comes from firing WM_CONTEXTMENU and the other is coming from WM_RBUTTONUP, somehow. If I comment out the WM_RBUTTONUP invoke, or the WM_CONTEXTMENU invoke, it works properly.
Actually scratch that. The issue probably lies in OnMouseEvent#L453.
This is the reason why the WM_RBUTTONUP msg triggered the ShowContextMenu function. Not sure if this is needed by the samples, but WM_CONTEXTMENU already covers for it.
Good find, I don't know if PR's are still actively being merged but you can try to PR the change?
I guess I can. I'll look into it a bit more later to check if there's a sample which uses that else block. Not sure what it was intended to cover if at all.