WPF XAML StringFormat DateTime:输出错误的文化? [英] WPF XAML StringFormat DateTime: Output in wrong culture?

查看:337
本文介绍了WPF XAML StringFormat DateTime:输出错误的文化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在DateTime值的输出中遇到麻烦。我的电脑目前的文化设置为de-AT(奥地利)。



以下代码

  string s1 = DateTime.Now.ToString(d); 
string s2 = string.Format({0:d},DateTime.Now);

结果s1和s2都具有正确的值30.06.2009。



但是在XAML中使用相同的格式

 < TextBlock Text ={ Binding Source = {x:Static sys:DateTime.Now},StringFormat = d}/> 

输出为6/30/2009。看起来XAML StringFormat忽略当前的文化设置。这是在Vista和XP上发生的。



我不想指定自定义格式,因为输出应该按照用户的首选文化设置进行格式化。 >

有同样问题的人吗?这是WPF中的错误吗?

解决方案

查看我对StringFomat本地化问题的回答


I'm having some trouble with the output of a DateTime value. My computer's current culture is set to de-AT (Austria).

The following code

string s1 = DateTime.Now.ToString("d");
string s2 = string.Format("{0:d}", DateTime.Now);

results in s1 and s2 both having the correct value of "30.06.2009".

But when using the same format in XAML

    <TextBlock Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat=d}"/>

the output is `"6/30/2009". It seems the XAML StringFormat ignores the current culture settings. This happens on both Vista and XP.

I don't want to specify a custom format, because the output should be formatted in the user's preferred culture setting.

Anybody with the same problem? Is this a bug in WPF?

解决方案

Please see my answer on StringFomat Localization problem

这篇关于WPF XAML StringFormat DateTime:输出错误的文化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆