microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.26k stars 673 forks source link

WinUI 3 Read access conflict #9186

Open Gaoyifei1011 opened 8 months ago

Gaoyifei1011 commented 8 months ago

Describe the bug

当应用窗口关闭时,会触发 Activated 事件,在此时访问 SystemBackdrop 时会提示读取访问权限冲突。

When the application window is closed, the Activated event is triggered. Against the SystemBackdrop, access conflict is prompted.

Steps to reproduce the bug

See describe

Expected behavior

The window is closed normally, and no access conflict is displayed

Screenshots

屏幕截图 2023-12-21 130114

NuGet package version

WinUI 3 - Windows App SDK 1.4.3: 1.4.231115000

Windows version

Windows 11 (22H2): Build 22621

Additional context

None

github-actions[bot] commented 8 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

DarranRowe commented 8 months ago

It is important to remember that the WM_ACTIVATE window message, and by extension the Window.Activated event, is used to indicate when the window is activated and deactivated. What this means is that, surprising as it is, the underlying HWND will get a WM_ACTIVATE with WA_INACTIVE when you close a window. It is therefore no surprise to find that the Xaml runtime filters this through and triggers the Activated event one last time. If you check the WindowActivatedEventArgs.WindowActivationState property, is this properly being set as WindowActivativationState.Deactivated? If it is then you are just getting caught out by this, and you probably need to use some other means, like AppWindow.Closing to not allow any problematic code to run.

Gaoyifei1011 commented 6 months ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment.

Please provide a relatively good solution