Xamarin XAML多语言在StringFormat中的应用

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

我有一个简单的(Android)应用程序在Xamarin。到目前为止,它只使用一种语言,现在我为第二种语言添加了一个翻译。我使用资源.resx文件,我在XAML中这样使用。

<Span Text="{x:Static resource:AppResources.Text1}" /> 

其中Text1从资源文件中加载(取决于语言)。我不知道如何在下一行中做类似的事情,在这里我使用Binding和StringFormat。

<Label Text="{Binding Datum, StringFormat='Some text: {0}'}" />

我试过用:

<Label Text="{Binding Datum, StringFormat='{x:Static resource:AppResources.Text2} {0}'}" />

但没有成功。

有什么办法吗?

xaml xamarin string-formatting
1个回答
1
投票

使用Spans来结合数据和文本

<Label>
  <Label.FormattedText>
    <FormattedString>
      <Span Text="{x:Static resource:AppResources.Text1}" />
      <Span Text="{Binding Datum}" />
    </FormattedString>
  </Label.FormattedText>
</Label>
© www.soinside.com 2019 - 2024. All rights reserved.