This is a migrated thread and some comments may be shown as answers.

Custom short date format

2 Answers 295 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
rcmp-grc
Top achievements
Rank 1
rcmp-grc asked on 03 Jul 2018, 04:48 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Vladimir Stoyanov
Telerik team
answered on 05 Jul 2018, 04:01 PM
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.
0
rcmp-grc
Top achievements
Rank 1
answered on 06 Jul 2018, 08:17 PM
Hi, yes I did have a look but wasn't sure about the binding. It works as presented, thanks.
Tags
DateTimePicker
Asked by
rcmp-grc
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
rcmp-grc
Top achievements
Rank 1
Share this question
or