首页 文章

Xamarin表单:TabbedPage中的ContentPages

提问于
浏览
5

我试图将一些自定义内容页面放入选项卡页面 . 遗憾的是,我不确定,如何使用XAML语法执行此操作 . 我的虚拟项目如下所示:

第1页

<?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 回答

  • 9

    你做错了 . 您必须将页面放置为TabbedPage Children .

    这是解决方案:

    <?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" });
        }
    }
    
  • -1

    您正在寻找TabbedPage上的Children属性

    <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 Title="Home">
        </ContentPage>
        <ContentPage Title="Browse">
        </ContentPage>
    </TabbedPage.Children>
    </TabbedPage>
    

相关问题