WPF XAML StringFormat:C# 4.0 中的文化解决方法被破坏?
周围的工作...
FrameworkElement.LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata(
XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
...过去一直有效(此处提到:StringFormat 本地化问题wpf)。
相反,直到我将应用程序从 3.5SP1 移植到 4.0 为止,它一直在工作。但现在在 4.0 中它又停止工作了。有人遇到过这种情况吗?
编辑:它现在甚至无法在 3.5SP1 中运行。我认为这与 4.0 的安装有关,因为之前它是有效的。
添加解决方法或删除它都不起作用。我什至尝试将...添加
CultureInfo.CurrentCulture.ClearCachedData();
this.Language = XmlLanguage.GetLanguage( CultureInfo.CurrentCulture.IetfLanguageTag);
到 Window 构造函数中。这也没有奏效。
The work around...
FrameworkElement.LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata(
XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
...used to work till now (mentioned here: StringFormat Localization issues in wpf).
Instead till I ported my application from 3.5SP1 to 4.0, it was working. But now in 4.0 it stopped working again. Anybody experiencing this?
EDIT: It is now not even working in 3.5SP1. I think this has something to do with the installation of 4.0 as previously this was working.
It is not working by either adding the workaround or removing it. I even tried adding...
CultureInfo.CurrentCulture.ClearCachedData();
this.Language = XmlLanguage.GetLanguage( CultureInfo.CurrentCulture.IetfLanguageTag);
to Window
constructor. This also didn't worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1. 确保尽早覆盖
LanguageProperty
的默认值。应用程序的静态构造函数是最好的选择。这很重要,因为BindingExpression
会缓存此属性的值,并且之后不会出于性能原因重新评估它。2.您的
CultureInfo.CurrentCulture
是什么?你确定这是你希望看到的吗?3. 如果您在树的上部某处指定
xml:lang
属性,则覆盖Language
属性元数据无效。例如,如果您说:无论您在属性元数据中设置什么,您都会获得意大利货币。
4. 如果您在绑定中指定
ConverterCulture
属性,则覆盖Language
属性元数据无效。例如,如果您说:
无论您在属性元数据或 < 中设置什么,您都会获得日元货币code>xml:lang 属性。据我所知,这种行为在框架之间没有改变。
希望这有帮助
1. Make sure you are overriding default value of
LanguageProperty
as early as possible. App's static constructor is the best bet. This is important becauseBindingExpression
caches value of this property and does not reevaluate it afterwards for performance reasons.2. What is your
CultureInfo.CurrentCulture
? Are you sure it's the one you expect to see?3. Overriding
Language
property metadata has no effect if you you specifyxml:lang
attribute somewhere upper in the tree. E.g. if you say:You'll get Italian currency no matter what you set in property metadata.
4. Overriding
Language
property metadata has no effect if you specifyConverterCulture
property in binding. E.g. if you say:<TextBlock Text="{Binding StringFormat=C, ConverterCulture=ja}"/>
you'll get Japanese currency no matter what you set either in property metadata or inxml:lang
attribute.This behavior was not changed between frameworks as far as I know.
Hope this helps