c# - Xamarin Forms - 在运行时翻译抽屉菜单项
问题描述
我正在关注 Xamarin.Forms 中多语言的优秀教程(链接)
一切都运行良好,但我有一个问题。
在我的应用程序中,我正在使用 Syncfusion 的导航抽屉,因为我在 ListView 中生成菜单项,如下所示。
DrawerPage.xaml
<ListView x:Name="listView"
SelectionMode="Single"
RowHeight="70"
ItemSelected="listView_ItemSelected"
SeparatorColor="Transparent">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Margin="32,10,0,0"
VerticalOptions="Center" >
<Grid RowDefinitions="1*, Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0"
Grid.Column="0"
HorizontalTextAlignment="Start"
HorizontalOptions="Start"
FontSize="25"
FontFamily="Material-Outlined"
Style="{StaticResource IconLabelStyle}"
Text="{Binding Icon}" />
<Label Grid.Row="0"
Grid.Column="1"
HorizontalTextAlignment="Start"
HorizontalOptions="Start"
Margin="10,0,0,0"
Text="{Binding Name}"
FontSize="16"/>
</Grid>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
抽屉页面.cs
private static string MAP = Lang.ResourceManager.GetString("Map");
private static string MAPICON = IconFont.ResourceManager.GetString("LocationOn");
private static string SETTINGS = Lang.ResourceManager.GetString("Settings");
private static string SETTINGSICON = IconFont.ResourceManager.GetString("Settings");
public partial class DrawerPage : ContentPage {
drawerNavItems();
}
private void drawerNavItems()
{
List<MenuItem> itemList = new List<MenuItem>();
itemList.Add(new MenuItem { Icon = MAPICON, Name = MAP });
itemList.Add(new MenuItem { Icon = SETTINGSICON, Name = SETTINGS });
listView.ItemsSource = itemList;
}
我遇到的问题是我不明白我应该如何使用上面教程链接中的帮助程序类来翻译抽屉菜单项。
在 Xaml 中,我们可以像这样翻译字符串
Text="{helpers:Translate Support}"
但是我如何在后面的代码中做同样的事情?
解决方案
推荐阅读
- python - 将文本文件读入字典
- python - 如何修复'TypeError:sort()的无效关键字参数'
- ios - Xcode 编译意外结果
- triggers - 尝试从元数据更新标准对象中的值
- android - renameTo 总是返回 false,即使我在 Manifest (ANDROID) 上使用 WRITE_EXTERNAL_STORAGE
- angular - 每 15 个字符换行一次
- windows - 直接 x 着色器的类型名称 ID3D10Blob 背后的词源是什么?
- r - 如何使用 R 取消数据集
- c# - .NET Core 3.0.0-preview5 上的 Blazor 中组件之间的导航
- codenameone - IOS Codenameone 应用程序每次在构建服务器上出错“符号:变量显示”