Repository navigation
[Windows] Allow early use of DeviceDisplay.Current.MainDisplayInfo - #14521
Conversation
…able ASAP This commit adds `OnPlatformWindowInitialized` to the WindowStateManager for Windows. This function sets the active window via the `OnPlatformWindowSubclassed` lifecycle event which happens before `OnActivated`, which is possible because we get a valid hWND in the `MauiWinUIWindow` constructor. As a result, users can now override `Application.CreateWindow` to set the window position and size before it's shown.
jfversluis
left a comment
There was a problem hiding this comment.
I think a lot of people will be happy with this one, thank you!
|
Can we name the files for test like the other ones, no underscores please. |
Co-authored-by: Rui Marinho <me@ruimarinho.net>
|
Thanks for applying the code review suggestions @jfversluis! |
|
How will I know which maui-windows workload version this fix will be included in? The latest version is 7.0.81/7.0.100 |
|
Would also like to know what version this fix will be applied to? Is this being saved for .NET 8? Hopefully will be delivered sooner. Can confirm that it's still an issue in the latest maui-windows workload version. |
|
I wonder if we should actually take a different approach. If there is no main window yet, then we can just use the main monitor on the system? I suppose the event is useful generally as it forms the same thing as an activity OnCreate... |
|
It's day two of me exploring .NET Maui ... And I run into fundamental stuff like this! The workaround solution offered here #6976 (comment) When will the fix be released? Here is another workaround. My issue is the redraw of the window that appears as flashing. But setting the window size to 0 in createWindow and then to the proper size and location in the Loaded event handler of the Page works. App.xaml.cs MainPage.xaml |
Description of Change
Currently (on Windows),
DeviceDisplay.Current.MainDisplayInfodoesn't get set until the first window is activated/shown on the screen since it uses the active window to gather this info.This PR fixes that by setting the active window as soon as possible using the
OnPlatformWindowSubclassedlifecycle event. This lifecycle event happens after we have a validHWNDbut before the window is "technically" active. I don't think this will cause any issues (???).As a result, Windows users can now do things like override
Application.CreateWindowto set the initial window position and size before it's shown without needing to pinvoke:Issues Fixed
Fixes #6976