我正在使用 TranslateExtension
来自 Xamarin。是否可以在调用中添加 StringFormat
?
目前,我有
<Label Text="{i18n:Translate User}" />
但是我需要这样的东西
<Label Text="{i18n:Translate User, StringFormat='{0}:'}" />
如果我做后者,我得到
Xamarin.Forms.Xaml.XamlParseException: Cannot assign property "StringFormat": Property does not exists, or is not assignable, or mismatching type between value and property
我知道我可以添加另一个带冒号的翻译,但最好有不同的选择。
最佳答案
晚会有点晚了,但是用标准扩展和 XAML 来做,像这样:
<Label Text="{Binding YourDynamicValue, StringFormat={i18n:Translate KeyInResources}}"/>
您的翻译应该类似于:静态文本{0}
。 {0}
替换为您绑定(bind)的值。
问题是 Translate
扩展只是从资源中获取您的字符串,并且没有 StringFormat
属性等。但是您可以分配检索到的资源Binding
的 StringFormat
的值。
关于xaml - 将 IMarkupExtension 与 StringFormat 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51047604/