Localise display format of dates

13 posts, 0 answers
  1. cocowalla
    cocowalla avatar
    15 posts
    Member since:
    Dec 2011

    Posted 18 Oct 2013 Link to this post

    How can we automatically display dates in the correct format for users, based on their Windows localisation settings?

    e.g.
    UK: 20/12/2013
    NO: 20.12.2013
    US: 12/20/2013
    etc
  2. cocowalla
    cocowalla avatar
    15 posts
    Member since:
    Dec 2011

    Posted 18 Oct 2013 Link to this post

    Sorry, I should have said I am actually using a RadGridView, with both read-only and editable date fields

    I've now got this working for the dates in display mode by setting this on the grid:

    IsLocalizationLanguageRespected="False"

    But when I edit dates the date format in the date picker is still wrong?
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 18 Oct 2013 Link to this post

    Hi Colin,

    The DatePicker by default uses the CurrentCulture of the user in order to format the date. You can easily check that if you change the culture of the computer then Clean/Rebuild the solution and run the application - the DatePicker changes the format. You can also the check the DateTimePicker Formatting article for more information.

    We'll investigate the scenario with RadGridView and we'll get back to you.

    Hope this helps.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  5. cocowalla
    cocowalla avatar
    15 posts
    Member since:
    Dec 2011

    Posted 18 Oct 2013 Link to this post

    Changing CurrentCulture seems to have no effect on DatePicker at all. When I check in code-behind I can see that the Culture property on the DatePicker is null.
  6. cocowalla
    cocowalla avatar
    15 posts
    Member since:
    Dec 2011

    Posted 18 Oct 2013 Link to this post

    Ah, disregard that last reply; it *is* changing the date format according to CurrentCulture.

    So the only problem I have remaining is that DatePickers in the GridView still don't display the correct format when in edit mode.
  7. cocowalla
    cocowalla avatar
    15 posts
    Member since:
    Dec 2011

    Posted 18 Oct 2013 Link to this post

    *sigh* please disregard my disregard!

    I've definately confirmed now that changing the CurrentCulture or CurrentUICulture doesn't affect the DatePicker Culture property.

    I have it set to nb-NO in Windows, and can confirm this by inspecting Thread.CurrentThread.CurrentUICulture and Thread.CurrentThread.CurrentCulture when debugging.

    But the Culture property of the DatePicker remains as 'en-GB' - presumably this is coming from a Language settings somewhere, as I still have English as my language in Windows. I don't want to change the language, or perform any localisation on text - only dates.
  8. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 18 Oct 2013 Link to this post

    Hi Colin,

    What I suggested was to change the Culture from the system settings and to observe the result. As for the scenario with the GridView you can set DataFormatString="d" of the GridViewDataColumn with the dates, this way the format will match the system settings. I have recorded and attached video to show the explained above.

    Please let us know if this works for you or we are missing something.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  9. cocowalla
    cocowalla avatar
    15 posts
    Member since:
    Dec 2011

    Posted 18 Oct 2013 Link to this post

    OK, now it's fully working for the GridView.

    But on other views I have 'standalone' DateTimePickers with DisplayFormat="Short", and it is still not working.

    At runtime I can see that Thread.CurrentThread.CurrentUICulture and Thread.CurrentThread.CurrentCulture are set to 'nbNO', but dates are still displayed in UK format (dd/mm/yyyy) and the Culture property of the DatePicker remains as 'en-GB' - presumably this is coming from a Language settings somewhere, as I still have English as my language in Windows. I don't want to change the language, or perform any localisation on text - only date formats.
  10. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 21 Oct 2013 Link to this post

    Hi Colin,

    In this case I can suggest you to try setting the Culture property of the DatePicker to null as showed below:
    Culture="{x:Null}"

    This way you will make sure the DatePicker is using the current culture of the computer, please also Clean/Rebuild the solution before running the project.

    Please try it and let us know if this has solved the described issue.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  11. cocowalla
    cocowalla avatar
    15 posts
    Member since:
    Dec 2011

    Posted 21 Oct 2013 Link to this post

    Yes, setting the Culture on the RadDateTimePicker to "{x:Null}" fixes this issue and shows dates in the correct format!

    It's going to be a real pain having to remember to set the culture to null on all date pickers... is this a bug?
  12. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 22 Oct 2013 Link to this post

    Hello Colin,
    If you haven't set anything to the Culture property of the DatePicker it is using the CurrentCulture of the CurrentThread. In other words the DatePicker should work correctly without setting the Culture to null. Please make sure you are not changing the culture somewhere else in the project.

    Hope this helps.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  13. cocowalla
    cocowalla avatar
    15 posts
    Member since:
    Dec 2011

    Posted 22 Oct 2013 Link to this post

    Ah, that was it! Someone had created a global style that set the culture to en-GB for all date pickers!
  14. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 22 Oct 2013 Link to this post

    Hi Colin,

    We are glad you have managed to resolve that.

    If you have any other questions let us know.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WPF is Visual Studio 2017 Ready