如何自定义主细节xamarin形式的页头

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

我显示主人的详细信息页面。

母版页有菜单项和详细信息页面的列表将所选项目的详细信息。

默认情况下,详细信息页面,在屏幕的左边显示的标题。我想自定义详细信息页面标题页面的中心显示。

反正是有定制的详细信息页面标题栏在Xamarin的形式?

截图附hereMaster page

enter image description here

xamarin xamarin.forms xamarin.ios xamarin.android
1个回答
1
投票

选项1:

我认为titleview的(available since XF 3.2)是你在找什么。所有你需要做的就是创建一个你想有作为titleview的,它ASIGN到NavigationPage作为视图:

public class TitleViewPage : ContentPage
{
    public TitleViewPage()
    {
        var titleView = new Slider { HeightRequest = 44, WidthRequest = 300 };
        NavigationPage.SetTitleView(this, titleView);
        ...
    }
}

XAML

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="NavigationPageTitleView.TitleViewPage">
    <NavigationPage.TitleView>
        <Slider HeightRequest="44" WidthRequest="300" />
    </NavigationPage.TitleView>
    ...
</ContentPage>

参考:https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical#displaying-views-in-the-navigation-bar

选项2:

早在天,titleview的是可用之前我曾经简单地删除导航栏:

NavigationPage.SetHasNavigationBar(this, false);

XAML

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             ...
             NavigationPage.HasNavigationBar="False">

然后,我只是把我的N​​avigationPage一个StackLayout(我的自定义标题栏)的顶部,所有的图标/按钮/图片/文本格式的/ etc,我想。

© www.soinside.com 2019 - 2024. All rights reserved.