WPF DatePicker日期不会与区域性切换 [英] WPF DatePicker date doesn't switch with culture

查看:145
本文介绍了WPF DatePicker日期不会与区域性切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上找到了,但是就像OP所说的那样,这是一种骇人听闻的解决方案,就像选票上所说的那样,不是一个漂亮的解决方案.我的程序只有一个窗口.

我有一个界面,其中包含2种可能的区域性,即de-DE和en-US,以及一个用于切换语言的按钮.

当我按下该按钮时,每个文本都会更改,只有DatePickers texbox中的文本不会更改,直到我单击DatePickers按钮,然后它将显示的日期更改为正确的格式(并打开DatePicker弹出窗口). /p>

如何使显示的日期与语言切换?我可以使用一些wpf选项来更新显示的日期吗?

它只有Binding是SelectedDate="{Binding Path=FileDate, Mode=TwoWay},并且到目前为止效果很好.

我尝试在语言切换上执行以下操作,但不会使文本更改:

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo((string)getSetting("Language"));
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo((string)getSetting("Language"));
FileDate = FileDate; //This one Notifies about the propertychange, so I hoped it would refresh the text.

解决方案

好,所以我有了另一个想法,它很好用,不像是hack,很容易做到:

切换语言时,除了设置CurrentCulture和CurrentUICulture之外,我还进行

FileDate = DateTime.Now;

这使DatePicker意识到文化已经改变.

I actually found this, but like the OP says it's a hacky solution, and like the votes say not a beautiful one. My program has one window.

I have a UI with 2 possible cultures, de-DE and en-US, and a button that switches the language.

Every text changes when I press that button, only the text in the DatePickers texbox doesn't, until I click on the DatePickers button, then it changes the shown date to the right format (and opens the DatePicker popup).

How can I make the shown date switch with the language? Isn't there some wpf option I can use to make it update the shown date?

Only Binding it has is SelectedDate="{Binding Path=FileDate, Mode=TwoWay}, and it works well so far.

I tried doing the following on switch of language, but it doesn't make the text change:

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo((string)getSetting("Language"));
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo((string)getSetting("Language"));
FileDate = FileDate; //This one Notifies about the propertychange, so I hoped it would refresh the text.

解决方案

Ok so I got another idea, and it works great, doesn't feel like a hack, and is easy to do:

When switching the language, beside setting the CurrentCulture and CurrentUICulture, I go

FileDate = DateTime.Now;

That apperently makes the DatePicker realize the Culture has changed.

这篇关于WPF DatePicker日期不会与区域性切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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