dotnet / dotnet/wpf

After Modified screen dpi,Unloaded/Loaded is trigged unexpectedly

Open
#2,255 2 comments 10 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

When I modify the system dpi in screen setting, a userControl in window raises unload event, as more amazing unload event of window that contains the userControl is not triggered.

As all I known, loaded/unloaded can be triggered by these cases:
FrameworkElement raises loaded/unloaded when it's added/removed to visual tree.
TabControl selection change from tab A to tab B, raise A'UnLoaded and B'Loaded
Expander、MenuItem and so on...All these cases, emmm.. seems like loaded/unloaded event raises just as element or it's parent leave from or add to wpf visual tree.

But, How Unloaded/Loaded can be raised by changing screen dpi ?
For testing, I create a window, then create and add a simple UserControl named A in window xaml, continue to create and add UserControl named B in A xaml. After window is showed in screen, modify screen dpi from 100% to 150%, UserControl A raise unloaded event, then UserControl B raise unloaded. As joking, window itself has no unloaded.
unloaded event stack:
![image](https://user-images.githubusercontent.com/21971433/69771912-65aa9c00-11c9-11ea-814a-1ac46f301e04.png)
As additional, before modify dpi setting, drag window and move near the taskbar, the issue occurs more probabily~
![image](https://user-images.githubusercontent.com/21971433/69771084-7e658280-11c6-11ea-9b98-3ccb08e42356.png)

More details please see my blog https://www.cnblogs.com/kybs0/p/11943313.html
Expecting you advise for this bug~

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.