Xamarin Forms 更改选项卡页面中的选项卡标题

Xamarin Forms Change Tab Title in Tabbed Page

我正在开发支持英语和阿拉伯语的 Xamarin 表单应用程序。我实现了翻译逻辑并且它工作正常,但我遇到了一个情况,我必须翻译标签页中的标签标题但没有 know-how。 所以问题是如何从 .cs 文件访问选项卡页面上的选项卡标题?提前致谢。

您的 TabbedPage 由多个 NavigationPages 组成。您需要设置 NavigationPage 的标题。这是 xaml:

的示例

标签页:

<?xml version="1.0" encoding="utf-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:local="clr-namespace:yourApp;assembly=yourApp"
        x:Class="yourApp.MainPage">

    <NavigationPage Title="Bottom Title (Page 1)">
        <x:Arguments>
            <local:Page1/>
        </x:Arguments>
    </NavigationPage>

    <NavigationPage Title="Bottom Title (Page 2)">
        <x:Arguments>
            <local:Page2/>
        </x:Arguments>
    </NavigationPage>

</TabbedPage>

还有一个导航页面:

<?xml version="1.0" encoding="utf-8"?>
<ContentPage 
       Title="Top Title (Page 1)" 
       xmlns="http://xamarin.com/schemas/2014/forms" 
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
       x:Class="yourApp.Page1">

</ContentPage>

有关详细信息,请查看 documentation

编辑:这里是 C# 的示例:

标签页:

public class MainPage : TabbedPage
{
    public MainPage ()
    {
        var page1 = new NavigationPage (new Page1());
        page1.Title = "Bottom Title (Page1)";
        var page2 = new NavigationPage (new Page2());
        page2.Title = "Bottom Title (Page2)";

        Children.Add (page1);
        Children.Add (page2);
     }
}

一个导航页面:

public class Page1 : ContentPage
{
    public Page1()
    {
        Title = "Top Title (Page1)";
    }
}