Xamarin表单更改选项卡页中的选项卡标题



我正在开发一款支持英语和阿拉伯语的Xamarin格式的应用程序。我实现了翻译逻辑,它运行得很好,但我遇到了一个案例,我必须在选项卡页面中翻译选项卡标题,但没有专业知识所以问题是如何从.cs文件访问选项卡页面上选项卡的标题提前谢谢。

您的TabbedPage由多个NavigationPage组成。您需要设置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>

有关更多信息,请查看文档

编辑:这里是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)";
}
}

最新更新