具有xamarin形式的多行标题的导航栏?

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

[嗨,我想在导航栏中实现多行标题。如何以xamarin形式进行操作。

我尝试使用换行符属性,但这不起作用。

Title="Morning \n 9.30 Am";

我想要这样的标题

早晨

9.30 Am

c# xamarin.forms newline navigationbar
1个回答
0
投票

如果要自定义页面中的导航栏,

例如,您想为其添加“标签”或“条目”。

您可以在Xamarin.Forms v3.2或更高版本中进行此操作

XForms引入了一个名为[NavigationPage.TitleView的新标记。

通过使用此标签,您可以自定义导航栏并将任何控件添加到导航栏

这里是将带有多行标签添加到导航栏中的示例代码。

在xaml

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
         x:Class="NavigationPageTitleView.AndroidExtendedTitleViewPage">
<NavigationPage.TitleView>
    <StackLayout>
        <Label x:Name="Label" 
               TextColor="Red" 
               FontSize="Medium"
               HorizontalTextAlignment="Center" />
    </StackLayout>
</NavigationPage.TitleView>

以cs为单位

 public MainPage()
    {
        InitializeComponent();
        Label.Text = "Line1\nLine2";
    }
© www.soinside.com 2019 - 2024. All rights reserved.