小编Joe*_*zer的帖子

Xamarin XAML x:对嵌套类中的属性的静态引用

我正在使用 Xamarin 编写一个移动应用程序,我有一个名为 Strings 的静态类,用于包装我的 RESX 资源。我想使用 x:Static 绑定到我的 XAML 文件中的这些。如果我有一个要绑定到的静态属性的静态类,这将起作用。

我删掉了一些评论和其他非必要的部分,但它基本上是这样的:

namespace MyCompany.Resources
{
    public static partial class Strings
    {
        public static string LabelUsername { get { return Resources.LabelUsername; } }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在我的 XAML 中,我像这样绑定到它:

<Entry Placeholder="{x:Static resources:Strings.LabelUsername}"

其中资源定义为

xmlns:resources="clr-namespace:MyCompany.Resources;assembly=MyCompany"

这一切正常。当我向字符串添加嵌套类时,它会崩溃。这个类看起来像这样:

namespace MyCompany.Resources
{
    public static partial class Strings
    {
        public static partial class Label
        {
            public static string Username { get { return Resources.Label_Username; } }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我这样做,那么我会像这样在我的 XAML 中绑定到它:

<Entry Placeholder="{x:Static resources:Strings.Label.Username}"
Run Code Online (Sandbox Code Playgroud)

注意在“resources:”之后我们现在有三个级别(Strings.Label.Username)。这似乎是失败的原因。当我这样做时,我收到编译错误: Type …

globalization resources xaml xamarin

1
推荐指数
1
解决办法
974
查看次数

标签 统计

globalization ×1

resources ×1

xamarin ×1

xaml ×1