【问题标题】:How to remove the navigation bar of a ContentPage when using Shell使用 Shell 时如何删除 ContentPage 的导航栏
【发布时间】:2021-09-04 14:31:39
【问题描述】:

我设置了一个注册/登录页面,我使用 shell 在它们之间导航,但我想删除标题(我不确定这是否是它的名称)

我已经尝试添加

NavigationPage.HasNavigationBar="false"

这在我的登录页面中,但没有效果。可能是因为我的 xaml 页面没有定义为导航页面。

这是我的 Login.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:viewmodel="clr-namespace:Appointments.ViewModels"  
             x:DataType="viewmodel:RegLogViewModel"
             x:Class="Appointments.Views.RegisterPage"
             NavigationPage.HasNavigationBar="false">

    <ContentPage.BindingContext>
        <viewmodel:RegLogViewModel/>
    </ContentPage.BindingContext>

    <Grid
            RowDefinitions="130,300,*,70">


        <Label
            Grid.Row="0"
            Text="REGISTRATION"
            HorizontalOptions="Center"
            VerticalOptions="Center"
            FontSize="40"
            />

        <StackLayout
            Grid.Row="1">

            <Entry Placeholder="username" Text="{Binding Name}"/>
            <Entry Placeholder="email" Text="{Binding Email}"/>
            <Entry Placeholder="password" Text="{Binding Password}"/>
            <Entry Placeholder="confirm password" Text="{Binding PasswordConfirmation}"/>
            <Entry Placeholder="phone number" Text="{Binding Phone}"/>

            <StackLayout Orientation="Horizontal">
                <Label 
                    Text="This account is for a hairstylist"
                    FontSize="20"/>
                <Switch/>
            </StackLayout>

        </StackLayout>

        <Button
            Grid.Row="2"
            Text="Register"
            FontSize="Large"
            VerticalOptions="Center"
            HorizontalOptions="CenterAndExpand"
            CornerRadius="10"
            Padding="20,0"
            BackgroundColor="Aquamarine"
            Command="{Binding LoginCommand}"
            
            />

        <Label
            Grid.Row="3"
            Text="Already a user? Login"
            FontSize="20"
            TextDecorations="Underline"
            HorizontalOptions="Center"
            VerticalOptions="Center"
>

            <Label.GestureRecognizers>
                <TapGestureRecognizer Command="{Binding GoToLoginCommand}"/>
            </Label.GestureRecognizers>

        </Label>

    </Grid>

</ContentPage>

我猜你只需要 ContentPage 定义

我已经在我的AppShell.xaml.cs 和我的AppShell.xaml 中注册了到这个页面的路由,我已经将ShellContent 设置为实际页面,就是这样。

【问题讨论】:

    标签: xaml xamarin.forms navigationbar xamarin.forms.shell


    【解决方案1】:

    由于您使用的是Shell,因此您需要设置Shell.NavBarIsVisible,而不是设置附加属性NavigationPage.HasNavigationBar

    <ContentPage ...
           Shell.NavBarIsVisible="False"
    

    相关问题

    How can you restrict/control the navigation routes the user can visit based on login status/role?

    【讨论】:

      猜你喜欢
      • 2018-12-22
      • 1970-01-01
      • 2014-11-23
      • 1970-01-01
      • 1970-01-01
      • 2015-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多