本文介绍了Xamarin表单:可以在内容页面上以编程方式在Shell App中添加选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过Google找到了,但找不到结果.
I finding through the google but could not find the result.
我有一个Shell设置Xamarin表单应用程序.尽管我没有完全使用它的功能,但是xaml文件中有一个选项卡设置.
I have a Shell setup Xamarin form application. Eventhough I am not fully use it's functionally but there is a tab setup in xaml file.
我想知道我能否在shellContent下托管一个内容页面,并从contentPage中添加选项卡.
I am wonder can i have a content page hosted under the shellContent and add Tabs from the contentPage.
推荐答案
是否要像这样的GIF实现它?
Do you want to achieve it like this GIF?
您可以像这样的代码在AppShell.xml
中为TabBar
添加x:Name.
You can add x:Name for TabBar
in AppShell.xml
like this code.
<TabBar x:Name="myTabBars">
<Tab Title="Browse" Icon="tab_feed.png">
<ShellContent ContentTemplate="{DataTemplate local:ItemsPage}" />
</Tab>
<Tab Title="About" Icon="tab_about.png">
<ShellContent ContentTemplate="{DataTemplate local:AboutPage}" />
</Tab>
</TabBar>
在AppShell.xml.cs
中,显示此选项卡.
public partial class AppShell : Xamarin.Forms.Shell
{
// public static Shell myshell;
public static TabBar mytabbar;
public AppShell()
{
InitializeComponent();
mytabbar = myTabBars;
}
}
在ContentPage
中使用它.
private void Button_Clicked(object sender, EventArgs e)
{
ShellSection shell_section = new ShellSection
{
Title = "home",
};
shell_section.Items.Add(new ShellContent() { Content = new HomePage() });
AppShell.mytabbar.Items.Add(shell_section);
}
这篇关于Xamarin表单:可以在内容页面上以编程方式在Shell App中添加选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!