2015-12-07 50 views
0

的我有我在App类的共享Xamarin.Forms应用程序的创建,像这样一个主页:Xamarin窗体导航页面回标签拖出标签背景

public App() 
{ 
    // The root page of your application 
    MainPage = new NavigationPage(new MainPage()); 
} 

在该主网页,我做其标签并创建两个孩子:

public partial class MainPage : TabbedPage 
{ 
    public MainPage() 
    { 
     InitializeComponent(); 
     this.Children.Add(new FirstPage()); 
     this.Children.Add(new SecondPage()); 
    } 
} 

第一页有送你到ThirdPage click处理:

TheButton.Clicked += async (object sender, EventArgs e) => { 
       await Navigation.PushAsync(new ThirdPage()); 
}; 

正如预期的那样,第三页有一个后退按钮,但是当我单击它时,它会将我返回到标签页上下文中的第一页。换句话说,我并没有回到标签页面的子页面,而是无法返回到标签页的单个子页面。

我可以忽略一些明显的东西吗?

+0

是您的 '第一页' 一NavigationPage或只是一个ContentPage? – Felix

回答

0

从您的主页面中删除导航页面。

public App() 
{ 
    // The root page of your application 
    MainPage = new MainPage(); 
} 

将导航页面添加到您的两个子页面。

public partial class MainPage : TabbedPage 
{ 
    public MainPage() 
    { 
     InitializeComponent(); 
     this.Children.Add(new NavigationPage(new FirstPage()) 
     { 
      Title = "First Page", 
      Icon = "FirstIcon.png" 
     }); 
     this.Children.Add(new NavigationPage(new SecondPage()) 
     { 
      Title = "Schedule", 
      Icon = "Schedule.png" 
     }); 
    } 
} 

更多信息参考:https://www.syntaxismyui.com/xamarin-forms-tabbedpage-navigation-recipe/

+0

这不适用于Android。这些标签仍然可以从ThirdPage中看到。 –

+1

当你导航.PopToRootAsync();'?时会发生什么? –