Hello,
Please open your MauiProgram.cs
, You can detect the window size changed by winuiAppWindow.Changed
event. Then detect maximaze or minimize page state the by OverlappedPresenterState
.
#if WINDOWS
builder.ConfigureLifecycleEvents(events =>
{
events.AddWindows(wndLifeCycleBuilder =>
{
wndLifeCycleBuilder.OnWindowCreated(window =>
{
IntPtr nativeWindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window);
WindowId win32WindowsId = Win32Interop.GetWindowIdFromWindow(nativeWindowHandle);
AppWindow winuiAppWindow = AppWindow.GetFromWindowId(win32WindowsId);
var p = winuiAppWindow.Presenter as OverlappedPresenter;
winuiAppWindow.Changed += (sender, args) => {
if(args.DidSizeChange)
{
OverlappedPresenterState res = p.State;
if (res == OverlappedPresenterState.Maximized)
{
// this will be invoked when maxmized button clicked
WeakReferenceMessenger.Default.Send(new StatusChangedMessage("Maximized"));
}
else if (res == OverlappedPresenterState.Minimized)
{
// this will be invoked when Minimized button clicked
WeakReferenceMessenger.Default.Send(new StatusChangedMessage("Minimized"));
}
else {
}
}
};
});
});
});
#endif
By the way, please do not forget to add these namespace in the MauiProgram.cs
#if WINDOWS
using Microsoft.Maui.LifecycleEvents;
using Microsoft.UI;
using Microsoft.UI.Windowing;
#endif
After that, you can send WeakReferenceMessenger from MauiProgram.cs to your specific pages. When winuiAppWindow.Changed get maximaze or minimize the page event, you can hide these controls when you get messages in detailed page.
// Create a message
public class StatusChangedMessage : ValueChangedMessage<string>
{
public StatusChangedMessage(string msg) : base(msg)
{
}
}
public NewPage1()
{
InitializeComponent();
// Register a message in some module
WeakReferenceMessenger.Default.Register<StatusChangedMessage>(this, (r, m) =>
{
var res=m.Value;
if (res.Equals("Maximized"))
{
}else if (res.Equals("Minimized"))
{
}
});
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.