2016-06-10 86 views
2

我正在尝试将一些自定义内容页面放入选项卡式页面。可悲的是我不确定,如何用XAML语法来做到这一点。我的虚拟项目如下所示:Xamarin表单:TabbedPage中的内容页

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="MyApp.Pages.Page1"> 
<Label Text="Page 1" VerticalOptions="Center" HorizontalOptions="Center" /> 
</ContentPage> 

页2完全相同。选项卡式页面:

<?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="MyApp.Pages.Navigation"> 
    <ContentPage x:Class="MyApp.Pages.Page1" Title="Home"> 
    </ContentPage> 
    <ContentPage x:Class="MyApp.Pages.Page2" Title="Browse"> 
    </ContentPage> 
</TabbedPage> 

页面不会显示出来吗?我怎样才能正确地做到这一点?

回答

2

你做错了。 您必须将页面作为TabbedPage儿童放置。

这里是解决方案:

<?xml version="1.0" encoding="utf-8" ?> 
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      xmlns:mypages="clr-namespace:MyApp.Pages;assembly=MyApp" 
      x:Class="MyApp.Pages.Navigation"> 
    <TabbedPage.Children> 
    <mypages:Page1 Title="Home"/> 
    <mypages:Page2 Title="Browse"/> 
    </TabbedPage.Children> 
</TabbedPage> 

在可替代的,你可以通过编程方式做到这一点:

public class TabsPage : TabbedPage 
{ 
    public TabsPage() 
    { 
     this.Children.Add (new Page1() { Title = "Home" }); 
     this.Children.Add (new Page2() { Title = "Browse" }); 
    } 
} 
0

您正在寻找Children属性上TabbedPage

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="MyApp.Pages.Navigation"> 
<TabbedPage.Children> 
    <ContentPage x:Class="MyApp.Pages.Page1" Title="Home"> 
    </ContentPage> 
    <ContentPage x:Class="MyApp.Pages.Page2" Title="Browse"> 
    </ContentPage> 
</TabbedPage.Children> 
</TabbedPage> 
相关问题