WPF XAML StringFormat:C# 4.0 中的文化解决方法被破坏?

发布于 2024-08-30 12:44:17 字数 755 浏览 3 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独自←快乐 2024-09-06 12:44:17

1. 确保尽早覆盖 LanguageProperty 的默认值。应用程序的静态构造函数是最好的选择。这很重要,因为 BindingExpression 会缓存此属性的值,并且之后不会出于性能原因重新评估它。

2.您的CultureInfo.CurrentCulture是什么?你确定这是你希望看到的吗?

3. 如果您在树的上部某处指定 xml:lang 属性,则覆盖 Language 属性元数据无效。例如,如果您说:

<StackPanel xml:lang="it">
  <TextBlock Text="{Binding StringFormat=C}"/>
</StackPanel>

无论您在属性元数据中设置什么,您都会获得意大利货币。

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 because BindingExpression 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 specify xml:lang attribute somewhere upper in the tree. E.g. if you say:

<StackPanel xml:lang="it">
  <TextBlock Text="{Binding StringFormat=C}"/>
</StackPanel>

You'll get Italian currency no matter what you set in property metadata.

4. Overriding Language property metadata has no effect if you specify ConverterCulture 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 in xml:lang attribute.

This behavior was not changed between frameworks as far as I know.

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文