UI.WPF.Modern icon indicating copy to clipboard operation
UI.WPF.Modern copied to clipboard

Context Menu does not work after PC Sleep / Lock

Open biocross opened this issue 5 months ago • 13 comments

Describe the bug

Hello, I am facing a specific issue where the context menus inside that window stop working after the system is locked and unlocked (or pc goes to sleep and unlocks after that)

I have created a sample project to reproduce the exact issue:

TestApp.zip

Reproduction

  • Run the project and ignore the MainWindow
  • Open your system tray, and you will see a small tray icon for app. Click that, and it will open Window1.
  • Inside the window1, you will see a button to open a menu. When you click that, a menu will open just fine.
  • Now put your computer on sleep or you can just lock it.
  • When you unlock your computer after sleep or lock, open the tray window (Window1) again. Then, try opening the menu by clicking the button inside Window1. The menu will not open. This is the issue.

Hopefully you have some pointers or ideas on how to fix this. I have been struggling with it for a while.

Suggested Solution

No response

Library Version

1.2.8

Operating System

Windows 11

Framework

.NET Core and .NET

Framework Version

7

Source of Package

NuGet.org (Package)

Additional Notes

No response

Validations

  • [x] Check that there isn't already an issue that reports the same or similar problem.
  • [x] Check that this is a bug in the library that should be fixed, not a feature, also this is not about the documentation. (Or please choose the right repo and template.)
  • [x] This is one single problem, or a few problems with the same cause. (If you want to report multiple problems, please create one issue for every single problem.)
  • [x] You've checked that this problem still exists in the latest version. (Keep in mind that we don't provide any support for old versions.)
  • [x] You know that we can't guarantee that we will satisfy your request. This is not really our duty to do everything anyone asks for. Also, you will treat our staff, contributors, and other users with respect and kindness.
  • [x] You're sure there's something wrong with the library itself, not how you're using it. (If you are having issues using it and need help, please go to discussion.)

biocross avatar Jul 16 '25 14:07 biocross

Possible duplicate of #179 ? Check if the latest release (v0.10.1) works for you.

NotYoojun avatar Jul 19 '25 13:07 NotYoojun

Hello, the latest version still does not work.

I saw the fix MR and looks like the fix is applied to individual components. Has the fix been applied to ui:DropDownButton?

biocross avatar Jul 22 '25 01:07 biocross

  • Library Version: 0.10.1
  • Operating System: Windows 10 22H2
  • Framework: .Net
  • Framework Version: 9.0
  • Source of Package: NuGet.org (Package)

I have a similar problem, there are two windows (main window, child window[settings window]) and tray icon

The problem phenomenon is the same as the one described in this project issue, or some clues can be found here.

Main window is normally hidden, child window is not open

  1. Normally the main window is out of focus and automatically hidden
private void OnDeactivated(object sender, EventArgs e)
{
    // Win32 api and wpf level modification window show different behavior, directly using Hide may lead to appear in the Alt-Tab bar
    Visibility = Visibility.Collapsed;
}
  1. Then lock the screen
  2. After unlocking normally, right click tray icon directly opens sub-window, and found that sub-window can be opened normally but cannot be clicked (ContextMenu can still be opened normally at this time)
  3. At this point as long as I open the main window can be restored

The main window is normally hidden, and the child window has been opened.

  1. After unlocking the lock screen, you cannot right-click to open ContextMenu, and the child window cannot be clicked (you can click on the upper right corner to close it, and there will be no MouseOver effect)
  2. Open the main window to restore

ZGGSONG avatar Oct 29 '25 14:10 ZGGSONG

  • Library Version: 0.10.1

    • Operating System: Windows 10 22H2

    • Framework: .Net

    • Framework Version: 9.0

    • Source of Package: NuGet.org (Package)

I have a similar problem, there are two windows (main window, child window[settings window]) and tray icon

The problem phenomenon is the same as the one described in this project issue, or some clues can be found here.

Main window is normally hidden, child window is not open

1. Normally the main window is out of focus and automatically hidden

private void OnDeactivated(object sender, EventArgs e) { // Win32 api and wpf level modification window show different behavior, directly using Hide may lead to appear in the Alt-Tab bar Visibility = Visibility.Collapsed; }

2. Then lock the screen

3. After unlocking normally, right click tray icon directly opens sub-window, and found that sub-window can be opened normally but cannot be clicked (ContextMenu can still be opened normally at this time)

4. At this point as long as I open the main window can be restored

The main window is normally hidden, and the child window has been opened.

1. After unlocking the lock screen, you cannot right-click to open ContextMenu, and the child window cannot be clicked (you can click on the upper right corner to close it, and there will be no MouseOver effect)

2. Open the main window to restore

I found a solution in the Flow.Launcher project

  • https://github.com/Flow-Launcher/Flow.Launcher/pull/3593
  • https://github.com/Flow-Launcher/Flow.Launcher/pull/3593/files#diff-221ad76e730453d0a7b7e189d87e2cc9c6d662ad841260c6ba53105633e8d75d
  • https://github.com/dotnet/wpf/issues/2158

ZGGSONG avatar Oct 30 '25 01:10 ZGGSONG

Image

🥹

ZGGSONG avatar Oct 30 '25 01:10 ZGGSONG

This seems weird, does it happen on the latest commit build of the repository?

NotYoojun avatar Oct 30 '25 13:10 NotYoojun

This seems weird, does it happen on the latest commit build of the repository?

It's been resolved. I found this code in the code base: https://github.com/iNKORE-NET/UI.WPF.Modern/blob/main/source/iNKORE.UI.WPF.Modern/Common/ShadowAssist.cs#L17

ZGGSONG avatar Oct 30 '25 13:10 ZGGSONG

It's been resolved. I found this code in the code base.

So we can happily close this issue as resolved?

NotYoojun avatar Oct 31 '25 00:10 NotYoojun

This issue is not mine. 😂

ZGGSONG avatar Oct 31 '25 02:10 ZGGSONG

Thanks for confirming. The earlier PR introduced ShadowAssist, which applies to controls that use BitmapCache. However, in this case the ui:DropDownButton itself doesn’t directly host a Popup - the Popup is created by YOU (when you write the <Flyout/> markdown).

The problem is the ui: MenuFlyout.

The example from @biocross is actually using ui:MenuFlyout. The previous PR only modified ui:Flyout, but ui:MenuFlyout is not derived from ui:Flyout; instead, both share the same base class ui:FlyoutBase.

That means the ShadowAssist logic currently only applies to ui:Flyout, leaving ui:MenuFlyout (and potentially other FlyoutBase-derived classes) out of sync. To make the behavior consistent, it probably makes sense to move the ShadowAssist integration up into FlyoutBase, so that all derived classes automatically respect the same shadow settings.

What do you think? @biocross @Jack251970

I'll start a branch to test it, perhaps?

NotYoojun avatar Oct 31 '25 16:10 NotYoojun

Thanks for confirming. The earlier PR introduced ShadowAssist, which applies to controls that use BitmapCache. However, in this case the ui:DropDownButton itself doesn’t directly host a Popup - the Popup is created by YOU (when you write the <Flyout/> markdown).

The problem is the ui: MenuFlyout.

The example from @biocross is actually using ui:MenuFlyout. The previous PR only modified ui:Flyout, but ui:MenuFlyout is not derived from ui:Flyout; instead, both share the same base class ui:FlyoutBase.

That means the ShadowAssist logic currently only applies to ui:Flyout, leaving ui:MenuFlyout (and potentially other FlyoutBase-derived classes) out of sync. To make the behavior consistent, it probably makes sense to move the ShadowAssist integration up into FlyoutBase, so that all derived classes automatically respect the same shadow settings.

What do you think? @biocross @Jack251970

I'll start a branch to test it, perhaps?

I think this is the root problem. Feel free to create a PR for it.

Jack251970 avatar Oct 31 '25 16:10 Jack251970

Which one should we modify, the FlyoutBase or the underlying PopupEx. A little bit short of ideas. Also, this issue is quite tricky cuz most of time I'm unable to reproduce it on my machine.

Would anyone be interested in proposing ideas, testing or draft a PR? That would be a huge help!

NotYoojun avatar Oct 31 '25 16:10 NotYoojun

I can help with testing.

biocross avatar Nov 01 '25 05:11 biocross