remember flyout choice.

Eduardo Gomez 3,431 Reputation points
2024-03-11T00:53:41.52+00:00

I have a shell and a viewModel

<Shell
    Title="DemyAI"
    FlyoutIsPresented="{Binding Status}"
    x:DataType="vm:AppShellViewModel"
    Shell.TabBarIsVisible="False">
    <ShellContent
        ContentTemplate="{DataTemplate pages:StartupPage}"
        Route="StartupPage"
        Shell.FlyoutBehavior="Disabled"
        Shell.FlyoutItemIsVisible="False" />
    <ShellContent
        ContentTemplate="{DataTemplate pages:LoginPage}"
        Route="LoginPage"
        Shell.FlyoutBehavior="Disabled"
        Shell.FlyoutItemIsVisible="False" />
    <ShellContent
        ContentTemplate="{DataTemplate pages:NoInternetPage}"
        Route="NoInternetPage"
        Shell.FlyoutBehavior="Disabled"
        Shell.FlyoutItemIsVisible="False" />
    <ShellContent
        ContentTemplate="{DataTemplate pages:RoleSelectionPage}"
        Route="RoleSelectionPage"
        Shell.FlyoutBehavior="Disabled"
        Shell.FlyoutItemIsVisible="False"
        Shell.NavBarIsVisible="False" />
 


My

FlyoutIsPresented="{Binding Status}"

is bound to my viewModel

public partial class AppShellViewModel(IAppService appService) : BaseViewModel {
    [ObservableProperty]
    bool status;
   partial void OnStatusChanged(bool value) {
       if (DeviceInfo.Current.Idiom == DeviceIdiom.Desktop) {
           Preferences.Default.Set(Constants.FLYOUT_STATUS, value);
       }
   }
public partial class AppShell : Shell {
    public AppShell(AppShellViewModel appShellViewModel) {
        InitializeComponent();
        BindingContext = appShellViewModel;
        RegisterPages();
    }
    private void RegisterPages() {
        Routing.RegisterRoute(nameof(JoinMeetingPage), typeof(JoinMeetingPage));
        Routing.RegisterRoute(nameof(RoleSelectionPage), typeof(RoleSelectionPage));
        Routing.RegisterRoute(nameof(LoginPage), typeof(LoginPage));
        Routing.RegisterRoute(nameof(NoInternetPage), typeof(NoInternetPage));
        Routing.RegisterRoute(nameof(ManageCoursePage), typeof(ManageCoursePage));
        Routing.RegisterRoute(nameof(NewLecturePage), typeof(NewLecturePage));
        Routing.RegisterRoute(nameof(NewTestPage), typeof(NewTestPage));
        Routing.RegisterRoute(nameof(NotificationsPage), typeof(NotificationsPage));
        Routing.RegisterRoute(nameof(RegisterStudentPage), typeof(RegisterStudentPage));
        Routing.RegisterRoute(nameof(ScheduleLecturePage), typeof(ScheduleLecturePage));
        Routing.RegisterRoute(nameof(ScheduleTestPage), typeof(ScheduleTestPage));
        Routing.RegisterRoute(nameof(WelcomePage), typeof(WelcomePage));
    }
   protected override void OnNavigating(ShellNavigatingEventArgs args) {
    if(DeviceInfo.Current.Idiom == DeviceIdiom.Desktop) {
        Preferences.Default.Get(Constants.FLYOUT_STATUS, false);
    }
    base.OnNavigating(args);
}

the problem is when I click the button for the first time, the status variable gets trigger, but when I click on a page, it will get trigger again.

what I want to do, is to remember my value when I navigate

for example, if I click the flyout button and the status be set to true I want the flyout to maintain open

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,722 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.