没有导航器导航栏没有显示titleView

问题描述 投票:0回答:2

Xamarin的新手,我正在尝试在我的跨平台应用程序中创建自定义导航栏。经过一些阅读后,我发现我可以在我的xaml页面文件中使用title-view组件,如下所示。

<?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="amici.MyGroups">
    <NavigationPage.TitleView>
        <StackLayout Orientation="Horizontal" VerticalOptions="Center" Spacing="10">
            <Label HorizontalOptions="StartAndExpand" Text="Left"/>
            <Label HorizontalOptions="CenterAndExpand" Text="Center"/>
            <Label HorizontalOptions="EndAndExpand" Text="Right"/>
        </StackLayout>
    </NavigationPage.TitleView>

    <ContentPage.Content>
        <ScrollView>
            <Grid x:Name="grid1">
                <StackLayout>
                        <Label Text="Welcome"
                        VerticalOptions="CenterAndExpand" 
                        HorizontalOptions="CenterAndExpand" />
                    </StackLayout>
                   <ActivityIndicator x:Name="WaitIcon"  IsRunning="{Binding IsBusy}" VerticalOptions="Center" HorizontalOptions="Center" />
            </Grid>
        </ScrollView>
    </ContentPage.Content>
</ContentPage>

我导航到我的页面“MyGroups”,如下所示:Navigation.PushAsync(new MyGroups());

但是,唯一显示的是带有后退图标箭头的默认导航页面?

不经意间我错过了什么,或者我不明白。这是否需要在应用程序级别完成?

xaml xamarin xamarin.forms
2个回答
2
投票

正如XAML所述: <NavigationPage.TitleView> .. </NavigationPage.TitleView>

您可以将完全自定义的View设置为NavigationBar,但是,这仅适用于NavigationPages。您的代码部分正确,因为您将NavigationPage.TitleView设置为不在NavigationPage上: Navigation.PushAsync(new MyGroups())

如果您将导航到NavigationPageNavigation.PushAsync(new NavigationPage(new MyGroups()))

你应该看到你的自定义NavigationPage.TitleView。但是,结果将取决于您当前的导航模型,最终可能会出现多个导航栏。那是因为你将NavigationPage嵌套在另一个NavigationPage中。

我强烈建议您阅读有关此主题的official documentation,以便您明白这一点。


0
投票

您也可以使用MainPage设置Navigation

MainPage = new NavigationPage(new PageName());
© www.soinside.com 2019 - 2024. All rights reserved.