Forms 如何在xamarin表单的导航抽屉中添加子菜单
我想为导航抽屉中的一个项目显示子菜单。我想为导航抽屉中的一个项目添加5个子菜单项 哪种方法是为项目添加子菜单的最佳且最简单的方法?我想在android和IOS应用程序中使用这个子菜单 MasterDetailPage.cs:Forms 如何在xamarin表单的导航抽屉中添加子菜单,forms,xamarin,navigation-drawer,submenu,Forms,Xamarin,Navigation Drawer,Submenu,我想为导航抽屉中的一个项目显示子菜单。我想为导航抽屉中的一个项目添加5个子菜单项 哪种方法是为项目添加子菜单的最佳且最简单的方法?我想在android和IOS应用程序中使用这个子菜单 MasterDetailPage.cs: public MainMasterDetailPage() { InitializeComponent(); NavigationPage.SetHasBackButton(this, false);
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 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>
publicmainmasterdetailpage()
{
初始化组件();
NavigationPage.SetHasBackButton(此选项为false);
SetHasNavigationBar(这个,false);
navigationDrawerList.ItemsSource=GetMasterPageList();
this.IsPresented=false;
详细信息=新导航页面(新仪表板选项卡bedpage());
}
所选菜单上的私有void(对象发送方,SelectedItemChangedEventArgs e)
{
变量项=(主页面列表)e.SelectedItem;
如果(item.Title==“设置”)
{
}
其他的
{
字符串dbPath=Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),“vssSQLite.db3”);
SQLiteConnection db=新的SQLiteConnection(dbPath);
db.DropTable();
Application.Current.MainPage.Navigation.PushAsync(newmainpage());
}
}
列表getMasterPageList()
{
返回新列表
{
新建MasterPageList(){Title=“Settings”,Icon=“Settings.png”},
新建主页面列表(){Title=“Logout”,Icon=“Logout.png”},
};
}
}
MasterDetailPage.Xaml:
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 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>
我想显示设置
项的子菜单项。如何为设置
项创建该子菜单
帮助我。您有两个选项,可以使用可绑定布局并为其设置填充,也可以使用嵌套的ListView/Collection视图 如果你要用的话,请参考我的 否则,如果您的需求是将其用作可扩展选项,请参考以下链接,这些链接可能会帮助您实现您的需求
- 。从本博客顶部下载工作演示
- 李>