Custom short date format

3 posts, 1 answers
  1. rcmp-grc
    rcmp-grc avatar
    13 posts
    Member since:
    Dec 2016

    Posted 03 Jul 2018 Link to this post

    I'm using MVVM pattern and would like to create a custom format for DateTimePicker of yyyy-MM-dd, how can I accomplish this? 
  2. Answer
    Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    460 posts

    Posted 05 Jul 2018 Link to this post

    Hello,

    I suppose that you have checked out the Defining a custom format part of the Formatting article in our documentation. Since the Culture property of the RadDateTimePicker is a dependency property, you can use the same approach with a binding. Here is what I have in mind:
    public class ViewModel
    {
         public ViewModel()
            {
                this.Culture = new CultureInfo("en-US");
                this.Culture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
            }
     
            private CultureInfo culture;
     
            public CultureInfo Culture
            {
                get { return culture; }
                set { culture = value; }
            }
    }

    <telerik:RadDateTimePicker DataContext="{StaticResource ViewModel}"
                                       Culture="{Binding Culture}"
                                       InputMode="DateTimePicker"  />

    Hope this helps.

    Regards,
    Vladimir Stoyanov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. rcmp-grc
    rcmp-grc avatar
    13 posts
    Member since:
    Dec 2016

    Posted 06 Jul 2018 in reply to Vladimir Stoyanov Link to this post

    Hi, yes I did have a look but wasn't sure about the binding. It works as presented, thanks.
Back to Top