我如何在导航抽屉中为xamarin表单添加子菜单

问题描述 投票:0回答:2

我想在导航抽屉中显示一项的子菜单。我想为导航抽屉中的一项添加5个子菜单项。

哪个是添加项目子菜单的最佳和最简便的方法?我想在Android和IOS应用程序中使用此子菜单。

MasterDetailPage.cs:

 public MainMasterDetailPage()
        {
            InitializeComponent();
            NavigationPage.SetHasBackButton(this, false);
            NavigationPage.SetHasNavigationBar(this, false);
            navigationDrawerList.ItemsSource = GetMasterPageLists();
            this.IsPresented = false;
            Detail = new NavigationPage(new DashboardTabbedPage());

        }

        private void OnMenuSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var item = (MasterPageList)e.SelectedItem;

            if (item.Title == "Settings")
            {

            }
            else
            {
                string dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "vssSQLite.db3");
                SQLiteConnection db = new SQLiteConnection(dbPath);
                db.DropTable<LoginSqlLiteM>();
                Application.Current.MainPage.Navigation.PushAsync(new MainPage());
            }
        }
        List<MasterPageList> GetMasterPageLists()
        {
            return new List<MasterPageList>
            {
                new MasterPageList() { Title = "Settings", Icon = "settings.png" },
                new MasterPageList() { Title = "Logout", Icon = "logout.png" },

            };
        }
    }

MasterDetailPage.Xaml:

<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                  xmlns:local="clr-namespace:VSS.MasterPages"
                  xmlns:local1="clr-namespace:VSS.Pages"
                  IsPresented="False"
             x:Class="VSS.MasterPages.MainMasterDetailPage">

    <MasterDetailPage.Master>
        <ContentPage Title="☰">
            <StackLayout BackgroundColor="#ffffff">
                <StackLayout Margin="25,10,25,0" Padding="0,15,0,15">
                    <Image Source="VSSIcon.png" HorizontalOptions="Center" HeightRequest="80" WidthRequest="80"></Image>
                    <Label Text="Sched.ly" TextColor="#1CA9FF" FontSize="Large"  HorizontalOptions="CenterAndExpand"></Label>
                    <Label Text="Always on Time " TextColor="#1CA9FF" FontSize="Large" FontAttributes="Italic"  HorizontalOptions="CenterAndExpand"></Label>
                </StackLayout>
                <ListView x:Name="navigationDrawerList"  
                  RowHeight="60"  
                  SeparatorVisibility="None"  
                  ItemSelected="OnMenuSelected"  
                  BackgroundColor="#2196F3">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <StackLayout VerticalOptions="FillAndExpand"  
                                 Orientation="Horizontal"  
                                 Padding="20,10,0,10"  
                                 Spacing="20">

                                    <Image Source="{Binding Icon}"  
                                     WidthRequest="30"  
                                     HeightRequest="30"  
                                     VerticalOptions="Center" />
                                    <Label Text="{Binding Title}"  
                                     FontSize="Medium"  
                                     VerticalOptions="Center"  
                                     TextColor="White"/>
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>
        </ContentPage>
    </MasterDetailPage.Master>

    <MasterDetailPage.Detail>
        <NavigationPage>
            <x:Arguments>
                <local:DashboardTabbedPage/>
            </x:Arguments>
        </NavigationPage>
    </MasterDetailPage.Detail>
</MasterDetailPage>

Please click here to see the navigation drawer image

我想显示Settings项目的子菜单项目。我该如何为settings项目创建子菜单?

forms xamarin navigation-drawer submenu
2个回答
1
投票

您有两个选择,可以使用可绑定布局并为其设置填充,也可以嵌套一个ListView / Collection View。


0
投票

您可以尝试将Listview与james did in here之类的分组标题一起使用>

© www.soinside.com 2019 - 2024. All rights reserved.