MAUI: Issue with displaying Flyout menu page

Sreenivasan, Sreejith 80 Reputation points
2025-10-14T05:51:17.85+00:00

My home page is a FlyoutPage with Flyout as menu and Detail as DashboardTabPage. There are 3 children in DashboardTabPage and the last tab is menu.

If I tap on menu once, the menu will open from left and if tap outside it hides. My problem is If I open it once and tap it again the menu is not opening again. After hiding the menu, still color of menu icon is blue(still the selected tab as menu), it should be black when closing the menu. If I choose some other tabs and choose menu, at that time the menu is opening.

Adding menu open/close code below:


void HandleCurrentPageChanged(object sender, EventArgs e)

{

    var i = Children.IndexOf(CurrentPage);

    Debug.WriteLine("Page No:" + i);

    var menuPageType = NavigationService.GetPageType<AppMenuViewModel>();

    if (CurrentPage.GetType() != menuPageType)

    {

        lastSelectedItemIndex = i;

        return;

    }

    MenuOpenClose(!menuIsOpen);

}

public void MenuOpenClose(bool isPresented)

{

    var masterpage = MainService.HomePage.Value as DashboardMasterPage;

    if (masterpage is DashboardMasterPage)

    {

        FlyoutPage homePage = masterpage;

        homePage.IsPresentedChanged -= HomePageIsPresentedChanged;

        homePage.IsPresentedChanged += HomePageIsPresentedChanged;

        homePage.IsPresented = isPresented;

        menuIsOpen = isPresented;

        CurrentPage = Children[lastSelectedItemIndex];

    }

}

This was a xamarin forms project and I migrated it to MAUI. How can I fix this. it is working fine on xamarin with the same code.

Developer technologies | .NET | .NET MAUI
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Le (WICLOUD CORPORATION) 3,495 Reputation points Microsoft External Staff
    2025-10-14T10:31:02.0666667+00:00

    Hello @Sreenivasan, Sreejith ,

    The problem you're experiencing occurs because the flyout state and tab selection are getting out of sync.

    Xamarin.Forms was more lenient with these state changes, but MAUI enforces stricter synchronization.

    The issue stems from several factors:

    1. Your menuIsOpen boolean is not properly synchronized with the actual flyout presentation state
    2. Subscribing/unsubscribing to IsPresentedChanged on every toggle creates timing issues
    3. Changing CurrentPage while the flyout is presenting can cause race conditions in MAUI

    Since I cannot see the full details, please use this as a reference for your implementation.

    public partial class DashboardTabPage : TabbedPage
    {
        private int _lastSelectedTabIndex = 0;
        private bool _isProcessingMenuToggle = false;
        private FlyoutPage _flyoutPage;
     
        public DashboardTabPage()
        {
            InitializeComponent();
            InitializeFlyoutHandling();
        }
     
        private void InitializeFlyoutHandling()
        {
            _flyoutPage = MainService.HomePage.Value as FlyoutPage;
           
            if (_flyoutPage == null)
            {
                throw new InvalidOperationException("HomePage must be a FlyoutPage");
            }
           
            _flyoutPage.IsPresentedChanged += OnFlyoutPresentedChanged;
        }
     
        private void OnFlyoutPresentedChanged(object sender, EventArgs e)
        {
            if (_isProcessingMenuToggle) return;
     
            var flyoutPage = (FlyoutPage)sender;
           
            // Reset tab selection when flyout closes externally (tap outside)
            if (!flyoutPage.IsPresented && IsCurrentPageMenuTab())
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    _isProcessingMenuToggle = true;
                    CurrentPage = Children[_lastSelectedTabIndex];
                    _isProcessingMenuToggle = false;
                });
            }
        }
     
        void HandleCurrentPageChanged(object sender, EventArgs e)
        {
            if (_isProcessingMenuToggle) return;
     
            var currentIndex = Children.IndexOf(CurrentPage);
           
            if (!IsCurrentPageMenuTab())
            {
                _lastSelectedTabIndex = currentIndex;
                return;
            }
     
            HandleMenuTabTap();
        }
     
        private async void HandleMenuTabTap()
        {
            if (_flyoutPage == null) return;
     
            _isProcessingMenuToggle = true;
     
            if (_flyoutPage.IsPresented)
            {
                _flyoutPage.IsPresented = false;
                await Task.Delay(50);
                CurrentPage = Children[_lastSelectedTabIndex];
            }
            else
            {
                _flyoutPage.IsPresented = true;
            }
     
            _isProcessingMenuToggle = false;
        }
     
        private bool IsCurrentPageMenuTab()
        {
            return CurrentPage?.GetType() == NavigationService.GetPageType<AppMenuViewModel>();
        }
     
        protected override void OnDisappearing()
        {
            base.OnDisappearing();
           
            if (_flyoutPage != null)
            {
                _flyoutPage.IsPresentedChanged -= OnFlyoutPresentedChanged;
            }
        }
    }
    

    Testing Recommendations:

    1. Test the flyout behavior on different platforms (iOS/Android)
    2. Verify that the tab color resets properly when flyout closes
    3. Ensure smooth animation without flickering
    4. Test rapid tapping scenarios

    I hope this helps. Let me know if you have any other questions.


Your answer

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