How to fix dynamic MAUI flyout menu in iOS showing "More"

Daniel Omilegan 0 Reputation points
2024-10-05T15:35:03.5866667+00:00

public async static Task AddFlyoutMenusDetails()

    {

        AppShell.Current.FlyoutHeader = new FlyoutHeaderControl();

        AppShell.Current.FlyoutBackgroundColor = Color.FromArgb("FFEF5023");

        var parentDashboardInfo = AppShell.Current.Items.Where(c => c.Route == nameof(ParentDashboard)).FirstOrDefault();

        if (parentDashboardInfo != null) AppShell.Current.Items.Remove(parentDashboardInfo);

        var teacherDashboardInfo = AppShell.Current.Items.Where(c => c.Route == nameof(TeacherDashboard)).FirstOrDefault();

        if (teacherDashboardInfo != null) AppShell.Current.Items.Remove(teacherDashboardInfo);

        var userInfo = App.UserInfo;

        if (App.UserInfo.ActiveRole.ToLower() == "parent")

        {

            var flyoutItem = new FlyoutItem()

            {

                Title = "Dashboard",

                Route = nameof(ParentDashboard),

                FlyoutDisplayOptions = FlyoutDisplayOptions.AsMultipleItems,

                Items =

                    {

                        new ShellContent

                        {

                            Title = "Dashboard",

                            FlyoutIcon = "home",

                            ContentTemplate = new DataTemplate(typeof(ParentDashboard)),

                            Route = "ParentDashboard"

                        },

                        new ShellContent

                        {

                            Title = "Teachers",

                            FlyoutIcon = "parents",

                            ContentTemplate = new DataTemplate(typeof(Teachers)),

                            Route = "Teachers"

                        },

                        new ShellContent

                        {

                            Title = "Messages",

                            FlyoutIcon = "chat",

                            ContentTemplate = new DataTemplate(typeof(RecentMessagesPage)),

                            Route = "RecentMessagesPage"

                        },

                        new ShellContent

                        {

                            Title = "Events & Notices",

                            FlyoutIcon = "events",

                            ContentTemplate = new DataTemplate(typeof(Events)),

                            Route = "Events"

                        },

                        new ShellContent

                        {

                            Title = "Pickup/Dropoff",

                            FlyoutIcon = "car",

                            ContentTemplate = new DataTemplate(typeof(PickupDropoffRequestsPage)),

                            Route = "PickupDropoffRequestsPage"

                        },

                        new ShellContent

                        {

                            Title = "Attendance",

                            FlyoutIcon = "homework",

                            ContentTemplate = new DataTemplate(typeof(ParentStudentAttendancePage)),

                            Route = "ParentStudentAttendancePage"

                        },

                        new ShellContent

                        {

                            Title = "Homework",

                            FlyoutIcon = "homework",

                            ContentTemplate = new DataTemplate(typeof(StudentHomeworks)),

                            Route = "StudentHomeworks"

                        },

                        //new ShellContent

                        //{

                        //    Title = "Exam Results",

                        //    FlyoutIcon = "exam",

                        //    ContentTemplate = new DataTemplate(typeof(ParentStudentResultPage))

                        //},

                        new ShellContent

                        {

                            Title = "Notifications",

                            FlyoutIcon = "notifications",

                            ContentTemplate = new DataTemplate(typeof(NotificationsPage)),

                            Route = "NotificationsPage"

                        },

                        new ShellContent

                        {

                            Title = "My School",

                            FlyoutIcon = "school",

                            ContentTemplate = new DataTemplate(typeof(SchoolProfile)),

                            Route = "SchoolProfile"

                        },

                        new ShellContent

                        {

                            Title = "Settings",

                            FlyoutIcon = "settings",

                            ContentTemplate = new DataTemplate(typeof(SettingsPage)),

                            Route = "SettingsPage"

                        },

                }

            };

            //if (!AppShell.Current.Items.Any(x => x.Route == nameof(PickupDropOff)))

            //{

            //    AppShell.Current.Items.Add(new ShellContent

            //    {

            //        Route = nameof(PickupDropOff),

            //        ContentTemplate = new DataTemplate(typeof(PickupDropOff)),

            //        FlyoutItemIsVisible = false

            //    });

            //}

            if (!AppShell.Current.Items.Contains(flyoutItem))

            {

                AppShell.Current.Items.Add(flyoutItem);

                if (Preferences.ContainsKey("NavigationID"))

                {

                    string id = Preferences.Get("NavigationID", "");

                    if (id == "notification")

                    {

                        await AppShell.Current.GoToAsync(nameof(NotificationsPage));

                    }

                    Preferences.Remove("NavigationID");

                }

                await Shell.Current.GoToAsync($"//{nameof(ParentDashboard)}");

            }

        }

        else if (App.UserInfo.ActiveRole.ToLower() == "teacher")

        {

            var flyoutItem = new FlyoutItem()

            {

                Title = "Dashboard",

                Route = nameof(TeacherDashboard),

                FlyoutDisplayOptions = FlyoutDisplayOptions.AsMultipleItems,

                Items =

                {

                    new ShellContent

                    {

                        Title = "Home",

                        FlyoutIcon = "home",

                        ContentTemplate = new DataTemplate(typeof(TeacherDashboard)),

                    },

                    new ShellContent

                    {

                        Title = "My Students",

                        FlyoutIcon = "student",

                        ContentTemplate = new DataTemplate(typeof(TeacherStudentsPage))

                    },

                    new ShellContent

                    {

                        Title = "Parents",

                        FlyoutIcon = "parents",

                        ContentTemplate = new DataTemplate(typeof(Parents))

                    },

                    new ShellContent

                    {

                        Title = "Messages",

                        FlyoutIcon = "chat",

                        ContentTemplate = new DataTemplate(typeof(RecentMessagesPage))

                    },

                    new ShellContent

                    {

                        Title = "Exams",

                        FlyoutIcon = "exam",

                        ContentTemplate = new DataTemplate(typeof(ResultSearchPage))

                    },

                    new ShellContent

                    {

                        Title = "Homework",

                        FlyoutIcon = "homework",

                        ContentTemplate = new DataTemplate(typeof(Homeworks))

                    },

                    new ShellContent

                    {

                        Title = "Attendance",

                        FlyoutIcon = "exam",

                        ContentTemplate = new DataTemplate(typeof(TeacherStudentAttendancePage))

                    },

                    new ShellContent

                    {

                        Title = "Events & Notices",

                        FlyoutIcon = "events",

                        ContentTemplate = new DataTemplate(typeof(Events))

                    },

                    new ShellContent

                    {

                        Title = "My School",

                        FlyoutIcon = "school",

                        ContentTemplate = new DataTemplate(typeof(SchoolProfile))

                    },

                    new ShellContent

                    {

                        Title = "Subjects",

                        FlyoutIcon = "exam",

                        ContentTemplate = new DataTemplate(typeof(Subjects))

                    },

                    new ShellContent

                    {

                        Title = "Notifications",

                        FlyoutIcon = "notifications",

                        ContentTemplate = new DataTemplate(typeof(NotificationsPage))

                    },

                    new ShellContent

                    {

                        Title = "Settings",

                        FlyoutIcon = "settings",

                        ContentTemplate = new DataTemplate(typeof(SettingsPage))

                    },

                }

            };

            if (!AppShell.Current.Items.Contains(flyoutItem))

            {

                AppShell.Current.Items.Add(flyoutItem);

                if (Preferences.ContainsKey("NavigationID"))

                {

                    string id = Preferences.Get("NavigationID", "");

                    if (id == "notification")

                    {

                        await AppShell.Current.GoToAsync(nameof(NotificationsPage));

                    }

                    Preferences.Remove("NavigationID");

                }

                await Shell.Current.GoToAsync($"//{nameof(TeacherDashboard)}");

            }

        }

    }
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,595 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.