问题
I finding through the google but could not find the result.
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.
I am wonder can i have a content page hosted under the shellContent and add Tabs from the contentPage.
回答1:
Do you want to achieve it like this GIF?
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>
In the AppShell.xml.cs
, expose this tabbar.
public partial class AppShell : Xamarin.Forms.Shell
{
// public static Shell myshell;
public static TabBar mytabbar;
public AppShell()
{
InitializeComponent();
mytabbar = myTabBars;
}
}
Use it in the 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);
}
来源:https://stackoverflow.com/questions/60518089/xamarin-form-can-add-tabs-in-shell-app-programmatically-on-the-contentpage