Hello,
By using the following code to listen to changes in the IsPresented property using data binding, you will get the expected changes regardless of whether you close the Flyout using the hamburger button or clicking outside the range.
Code sample:
namespace MauiApp9
{
public partial class AppShell : Shell, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private bool isPresent;
public bool IsPresent
{
get { return isPresent; }
set
{
if (value != isPresent)
{
isPresent = value;
Console.WriteLine(value);
OnPropertyChanged();
}
}
}
public void OnPropertyChanged([CallerMemberName] string name = "") =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
public AppShell()
{
InitializeComponent();
BindingContext = this;
IsPresent = true;
}
}
}
in code-behind:
<Shell
x:Class="MauiApp9.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp9"
Shell.FlyoutBehavior="Flyout"
FlyoutIsPresented="{Binding IsPresent}"
Title="MauiApp9">
<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />
</FlyoutItem>
</Shell>
Best Regards,
Alec Liu.
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.