wpf-notifyicon icon indicating copy to clipboard operation
wpf-notifyicon copied to clipboard

Opening Context Menu instantly closes again

Open svr333 opened this issue 3 years ago • 6 comments

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="&#xF8B0;" />
                    </MenuItem.Icon>
                </MenuItem>
                <Separator />
            </ContextMenu>
        </tb:TaskbarIcon.ContextMenu>
    </tb:TaskbarIcon>

svr333 avatar Jul 14 '22 17:07 svr333

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?

Lakritzator avatar Sep 19 '22 13:09 Lakritzator

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?

svr333 avatar Sep 19 '22 21:09 svr333

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.

NPatch avatar Nov 11 '22 17:11 NPatch

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.

NPatch avatar Nov 11 '22 18:11 NPatch

Good find, I don't know if PR's are still actively being merged but you can try to PR the change?

svr333 avatar Nov 16 '22 14:11 svr333

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.

NPatch avatar Nov 16 '22 14:11 NPatch