Reputation: 2224
I have 3 tabbed pages inside the Xamarin forms. Such as Tab1 Tab2 and Tab3. Inside the Tab1 having the 1 button click on this button click, I am opening the new page.
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MyTabbedpage: TabbedPage
{
public MyTabbedpage()
{
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new MyContentPage());
}
}
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyTabbedpage"
>
<ContentPage x:Name="MySchedule" Title="Tab1" Icon="Calender.png">
<StackLayout>
<Button Clicked="Button_Clicked" Text="Test"></Button>
</StackLayout>
</ContentPage>
<ContentPage x:Name="Submission" Title="Tab2">
<StackLayout>
</ListView>
</StackLayout>
</ContentPage>
<ContentPage x:Name="Code" Title="Tab3">
</ContentPage>
</TabbedPage
While clicking on the button it navigates me on MyContentPage. at that time my tab page is hidden bcoz I am navigating to the new page. But I want that Tabbed pages as it is on MyContentPage. How Can I do this?
Upvotes: 0
Views: 117
Reputation: 12179
In this case, each Tab
should be wrapped by a NavigationPage
and PushAsync
method should be called not on the TabbedPage
level but on its children level.
Example:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyTabbedpage">
<TabbedPage.Children>
<NavigationPage x:Name="MySchedule" Icon="Calender.png" Title="Tab1">
<x:Arguments>
<ContentPage >
<StackLayout>
<Button Clicked="Button_Clicked" Text="Test"></Button>
</StackLayout>
</ContentPage>
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MyTabbedpage: TabbedPage
{
public MyTabbedpage()
{
InitializeComponent();
}
async void Button_Clicked(object sender, EventArgs e) =>
await MySchedule.Navigation.PushAsync(new MyContentPage());
}
More information about Hierarchical Navigation
can be found here.
Upvotes: 1