-
-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Suggestion: Add WindowStateChanged
event
#112
Comments
Nice idea. Could you share what the use case is for that? As in what is a good example of why you’d need to know that? That’ll help me understand the best way to expose it |
One use case is that some of my application have custom code to handle minimizing to the system tray. This is configurable so the user can choose whether to minimize to the tray or minimize normally. To facilitate this my application needs to know when the user minimizes the application so it can act according to the users preference. This is why I added the WindowStateChanged event. Another use case is that I have applications that use custom code for persisting the window size, position, and state. That code needs to be able to check the current state of the window. The IsMinimized, IsNormal, and IsMaximized properties are mainly for cases where I want to use the window state in xaml bindings. I found these properties to be easier than trying to bind to the WindowState property. |
The second use case is already covered by WinUIEx with the Persistence api |
Current state is available here: https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.windowing.overlappedpresenter.state?view=windows-app-sdk-1.2#microsoft-ui-windowing-overlappedpresenter-state so only the event seems to be missing |
Thank you so much for the quick replies. I will check out the PersistenceStorage. I didn't realize that it supports unpackaged applications. It also looks like the OverlappedPresenter.State property will meet my needs for checking the current state. I definitely like not reinventing the wheel. |
Well sort of. You still need to provide the saving/loading from disk when unpackaged. Here’s one simple example of it: WinUIEx/src/WinUIExSample/App.xaml.cs Line 56 in 81bbfbc
|
I tested the PersistanceStorage and it works great! Saving/loading from disk was no problem since I already had that infrastructure in place. Now I am going to dive into window presenters to see what I have been missing out on there. |
WindowStateChanged
event
For now you can subscribe to the min/max/restore like this: var manager = WindowManager.Get(this);
manager.WindowMessageReceived += WindowMessageReceived;
// ...
private void WindowMessageReceived(object sender, WindowMessageEventArgs e)
{
if(e.Message.MessageId == 0x0005) //WM_SIZE
{
// https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-size
switch (e.Message.WParam)
{
case 0: Debug.WriteLine("Restored"); break;
case 1: Debug.WriteLine("Minimized"); break;
case 2: Debug.WriteLine("Maximized"); break;
}
}
} |
Now available in v2.3 release |
WinUIEx already includes methods to change the window state (Maximize, Minimize, Restore). To compliment these it would be nice to have properties to easily check the current state of the window. As a workaround I created a class that inherits from WindowEx and adds the following:
In order to make some xaml bindings easier I also added the following properties:
While my workaround works fine for me. It would be nice to have this functionality available in WinUIEx itself.
I have attached a small project that illustrates my implimentation.
WindowStateReportingDemoForWinUiEx.zip
The text was updated successfully, but these errors were encountered: