2016-06-10 84 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> 
相關問題