WPF DatePicker date doesn't switch with culture

╄→尐↘猪︶ㄣ 提交于 2020-01-05 09:11:31

问题


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.

回答1:


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.




回答2:


In addition to answer of squirrelkiller I would like to mention that the DatePicker (.net 4.6.1) also does not automatically take CurrentUICulture.DateTimeFormat.FirstDayOfWeek. It has to be set per Datepicker instance indiviually. I posted this also here



来源:https://stackoverflow.com/questions/39096350/wpf-datepicker-date-doesnt-switch-with-culture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!