【问题标题】:Cannot assign property "Text": type mismatch between "Xamarin.Forms.Binding" and "System.String"无法分配属性“文本”:“Xamarin.Forms.Binding”和“System.String”之间的类型不匹配
【发布时间】:2016-06-29 20:59:10
【问题描述】:

我想本地化我的应用程序,所以我正在使用 IMarkupExtension。

[ContentProperty ("Text")]
public class TranslateExtension : IMarkupExtension
{
    ...
    public string Text { get; set; }

    public object ProvideValue (IServiceProvider serviceProvider)
    {
        if (Text == null)
            return "";
        ...
        return translation;
    }
}

我的 XAML

  <Label Text="{extensions:Translate Text={Binding Title}}"/>

调试时出现错误

无法分配属性“文本”:类型不匹配 “Xamarin.Forms.Binding”和“System.String”

我该如何解决?

【问题讨论】:

    标签: c# xamarin xamarin.forms


    【解决方案1】:

    你可以试试这个:

    <Label Text="{extensions:Translate Title}"/>
    

    【讨论】:

    • 意思是“标题”的意思。我想要翻译 TitleProperty 的值。
    • 你确定吗?我在 AppResources.resx 文件对中有 Name = TitleValue = Alloha。扩展把 Alloha.
    • 我想,你正在使用:var manager = new ResourceManager(ResourceId, typeof(TranslatorExtension).GetTypeInfo().Assembly); var translation = temp.GetString(Text, ci); 它返回值是Name
    • 你说得对。我指的是Localizing XAML。我在 LoginViewModel 中有名为 Title 的属性,其中将包含问候语。就像你好,早上好,G9 ......
    • 您必须按照文章中的说明对每个本地化使用 RESX 文件
    猜你喜欢
    • 2017-08-27
    • 2019-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多