【问题标题】:How to pass a string value from resource file to a ConverterParameter?如何将字符串值从资源文件传递到 ConverterParameter?
【发布时间】:2017-12-18 15:10:26
【问题描述】:

我想传递这个资源,代码如下:

AppResources.lbCountry;

这里是ConverterParameter

<Label Text="{Binding SelectedCountry.Name, Converter={StaticResource nullToResourceConv}, ConverterParameter={--}}"  >

编辑

lbCountryAppResources:

internal static string lbCountry {
            get {
                return ResourceManager.GetString("lbCountry", resourceCulture);
            }
        }

Resx命名空间定义:

xmlns:Resx="clr-namespace:XamApp.Resources"  

但这不起作用:

ConverterParameter={x:Static Resx:AppResources.lbCountry}}

错误:

x:Static: 无法找到公共静态字段、静态属性、 Resx:AppResources 中名为 lbCountry 的 const 或枚举值

【问题讨论】:

  • 错误提示找不到public字段,请尝试将其更改为public

标签: c# xamarin mvvm xamarin.forms ivalueconverter


【解决方案1】:

试试这个:

ConverterParameter={x:Static myNameSpace:AppResources.lbCountry}

还要确保属性是public

【讨论】:

  • 我收到此错误:x:Static: 无法在 Resx:AppResources 中找到名为 lbCountry 的公共静态字段、静态属性、常量或枚举值
  • @MohamedAhmed lbCountry 是静态的吗?您的 Resx xmlns 是什么样的(XAML 页面中Resx 的命名空间声明)?
  • 我已经修改了问题
  • @MohamedAhmed 错误提示找不到public字段,所以尝试将其更改为public
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-16
  • 1970-01-01
  • 1970-01-01
  • 2017-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多