Fix blank space in .NET MAUI Shell when FlyoutBehavior is Locked by dynamically adjusting the layout.
When the Flyout in a Shell page is set to Locked, there is a blank space below the Flyout. To resolve this, dynamically adjust the Flyout type in the window events.
Add an event for window size changes
namespaceRuiChao.App{publicpartialclassApp:Application{publicApp(){InitializeComponent();Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Ngo9BigBOggjHTQxAR8/V1NHaF1cWWhIfEx1RHxQdld5ZFRHallYTnNWUj0eQnxTdEZiW35ccHdQR2VcUEN/Xw==");}protectedoverrideWindowCreateWindow(IActivationState?activationState){varsize=WindowControl.GetOprationSystemResolution();if(Config.Desktop){intwidth=1380;intheight=768;DesktopShell?desktopShellService=Handler.MauiContext!.Services.GetService<DesktopShell>();if(desktopShellService!=null){Windowwindow=newWindow(desktopShellService){Width=width,Height=height,X=(size.Width-width)/2,Y=(size.Height-height)/2};window.SizeChanged+=Window_SizeChanged;window.Destroying+=(s,e)=>{// Custom logic};returnwindow;}else{returnnewWindow(newDesktopShell(null!)){Width=width,Height=height,X=(size.Width-width)/2,Y=(size.Height-height)/2};}}elsereturnnewWindow(newMobileShell()){Width=700,Height=500,X=100,Y=100};}privatevoidWindow_SizeChanged(object?sender,EventArgse){Windowwindow=(Window)sender!;DesktopShellshell=(DesktopShell)window.Page!;// The method below is defined in DesktopShellshell.DesktopShell_SizeChanged(window.Height);//window.Page!.HeightRequest = window.Height;}}}
usingRuiChao.App.ViewModels;usingRuiChao.Resource.Classes.Maui;namespaceRuiChao.App{publicpartialclassDesktopShell:BaseShell<DesktopShellViewModel>{publicDesktopShell(DesktopShellViewModeldesktopShellViewModel):base(desktopShellViewModel){InitializeComponent();Navigated+=DesktopShell_Navigated;Navigating+=DesktopShell_Navigating;}privatevoidDesktopShell_Navigating(object?sender,ShellNavigatingEventArgse){CurrentPage.SizeChanged-=CurrentPage_SizeChanged;}privatevoidDesktopShell_Navigated(object?sender,ShellNavigatedEventArgse){CurrentPage.SizeChanged+=CurrentPage_SizeChanged;}privatevoidCurrentPage_SizeChanged(object?sender,EventArgse){grid.HeightRequest=CurrentPage.Height;}publicvoidDesktopShell_SizeChanged(doubleheight){Task.Delay(1000);if(CurrentPage!=null){grid.HeightRequest=CurrentPage.Bounds.Height;}if(FlyoutBehavior!=FlyoutBehavior.Locked){// May cause a "Converter failed" errorFlyoutBehavior=FlyoutBehavior.Locked;}//CurrentPage.SizeChanged -= Button_Clicked_4;//CurrentPage.SizeChanged += Button_Clicked_4;}}}