无法使用Xamarin Shell创建页面

时间:2019-08-14 23:25:38

标签: xamarin

我创建了Xamarin Shell页面,当我运行项目时,失败的System.InvalidOperationException:'ShellContent内容应为Page类型。出现标题页1,Route ShellContent2'。

<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:pages="clr-namespace:Project"
             xmlns:views="clr-namespace:Project"
             x:Class="Project.MyApp">    

    <FlyoutItem Title="Test">
        <Tab Title="Tab one">
            <ShellContent Title="Page 1">
                <views:page1 />
            </ShellContent>
        </Tab>
        <Tab Title="Tab two">
            <ShellContent Title="Page 2">
                <pages:page2 />
            </ShellContent>
        </Tab>
    </FlyoutItem>

</Shell>

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace Project
{
    public partial class MyApp : Shell
    {
        public MyApp()
        {
            InitializeComponent();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我用TabBar代替了FlyoutItem

<Shell xmlns="http://xamarin.com/schemas/2014/forms" 
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
   xmlns:d="http://xamarin.com/schemas/2014/forms/design"
   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
   mc:Ignorable="d"
   xmlns:local="clr-namespace:APP.Views"
   xmlns:vm="clr-namespace:APP.ViewModels"
   x:Class="APP.AppShell">

<TabBar>
    <Tab Title="{Binding TitleSignIn}" Icon="enter.png">
        <ShellContent ContentTemplate="{DataTemplate local:SignIn}" />
    </Tab>
    <Tab Title="{Binding TitleSignUp}" Icon="add_user.png">
        <ShellContent ContentTemplate="{DataTemplate local:SignUp}" />
    </Tab>
    <Tab Title="{Binding TitlePassword}" Icon="password.png">
        <ShellContent ContentTemplate="{DataTemplate local:ResetPassword}" />
    </Tab>
    <Tab Title="{Binding TitleAbout}" Icon="about.png">
        <ShellContent ContentTemplate="{DataTemplate local:About}" />
    </Tab>
</TabBar>

包含内容的页面位于视图内,并设置为ContentPage