【问题标题】:Setting ConverterCulture using x:Static使用 x:Static 设置 ConverterCulture
【发布时间】:2016-05-12 12:18:03
【问题描述】:

我正在尝试解决一个问题,但突然之间:



怎么了?它是可编译的,并且似乎可以在运行时正常工作。重新启动 VS 没有帮助,xaml 设计器一直说“无效标记”。


Xaml:

<Window x:Class="WpfApplication1.MainWindow"
        ...
        xmlns:SystemGlobalization="clr-namespace:System.Globalization;assembly=mscorlib">
    <TextBlock Text="{Binding Test, ConverterCulture={x:Static SystemGlobalization:CultureInfo.CurrentCulture}}" />
</Window>

编译器错误:

成员“CurrentCulture”无法识别或无法访问。

更多细节:

  • VS 2015
  • .Net Framework 4.5

【问题讨论】:

  • 对我有用,在 VS2010 或 VS2013 中没有错误
  • @MartinPrediger,感谢您找到重复项,但它没有接受的解决方案,并且没有任何答案有帮助,例如我必须以4.5 为目标,并且由于issue,我正试图从自定义绑定切换到xaml。

标签: c# wpf xaml


【解决方案1】:

@Sinatr,CurrentCulture 是只读属性。所以你可以使用

Text="{Binding Test,ConverterCulture={x:Static SystemGlobalization:CultureInfo.DefaultThreadCurrentCulture}}"

【讨论】:

  • 我需要在 App.cs 上将值设置为 DefaultThreadCurrentCulture(为空)刚刚添加:CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CurrentCulture; 在 app.cs c'tor 下
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-27
  • 2016-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-23
相关资源
最近更新 更多