locked
Update TimePicker to current PrimaryLanguageOverride

    Question

  • TimePicker formats itself using the value of Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride. When the user changes their preferred culture within my app, I update this property. I also want the TimePicker to dynamically reflect the new culture. Unfortunately, TimePicker doesn't automatically do this. I tried provoking an update by calling every layout method I could find on TimePicker, from ApplyTemplate on down, but nothing worked.
    Wednesday, April 22, 2015 1:14 AM

All replies

  • Hi Qnomad,

    It's a often asked question, the question can be summarized how we can change the culture information on runtime.

    You may want to see a interesting blog: https://timheuer.com/blog/archive/2013/03/26/howto-refresh-languages-winrt-xaml-windows-store.aspx

    Basically we need to add following code after the culture has been changed:

    var resourceContext = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView();
    resourceContext.Reset();
    

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, April 24, 2015 3:40 AM
    Moderator

  • Thanks for the reply, Jamles, however that code you posted doesn't resolve the issue.  I read the blog post you linked to as well.  Note that I am not asking how to dynamically update language text when the language changes.  I have that working fine already by raising PropertyChanged events from the view-model.  Rather, I am asking how to get DatePicker and TimePicker to update their formats when the language changes.
    Friday, April 24, 2015 9:23 PM
  • Hi Qnomad,

    We can use DataTimeFormatter class to set format template or use custom template. See it in details from this reference. https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.globalization.datetimeformatting.datetimeformatter.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1.

    In this case, you are able to get the current language when it changes. Next I think you can use the above link to format dates and times according to current language.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 27, 2015 7:51 AM
    Moderator
  • What exact code are you asking me to try?  Yes, I already know when the current language changes.  I can't find any properties on TimePicker or DatePicker of type DateTimeFormatter.  I did try setting the various "Format" properties on the DatePicker, but they have no effect after the control is displayed.  Also, setting the "Language" property on either displayed control doesn't change anything.

    Let me try to explain the scenario to you again.  I have TimePicker and DatePicker controls already displayed on the screen.  The user changes their preferred language.  I detected that fact.  I want to respond by correctly formatting the TimePicker and DatePicker controls that are already displayed on the screen, to match the new language.

    Monday, April 27, 2015 1:12 PM