I have WPF DatePicker In My UserControl and I want to display date as MMM-DD format.
I am using MVVM Pattern.
Any One faced this issue.
There us a lot of topic about that whit more or less hacking of the control but may be you could try the DateTimePicker from the WPF Toolkit which has 2 properties 'Format' and 'FormatString'
Like it's describe in this another post.
Set Format=Custom
And FormatString="youre custom format" like "dd::MMM::yyyy hh-mm-ss" or what ever you need
Related
I would like users to have an ability to type in dates in datepicker control. The two formats allowed are MMDDYYYY or MMDDYY, by default it is not possible to do it without slash
Dealing with this myself. Decided I wanted more of a "maskedtextbox" serving as my textbox versus the datepickertextbox. I had to include WPFToolkit for the maskedtextbox control. Then, I created a new class that inherits from Datepicker and added a few dependencyproperties. From there I created a resourcedictionary for the XAML of how to display this new custom date picker. You can build You'll lose the watermark but you gain a mask which I think is more user friendly.
You won't be able to accomplish what you are looking for without a custom control since Datepicker is tightly synced together where the selected Calendar date is an actual date and SelectedDate has to also be a date and the format MMDDYYYY isn't considered a date.
I managed to accomplish that easily with telerik's RadDatePicker. Setting AllowParsingWithoutSeparator="True" property resolved my issue. The other solution is to have a textbox with mask.
I have set two different cultures to the thread as:
Thread.CurrentThread.CurrentCulture = "fi-FI"
Thread.CurrentThread.CurrentUICulture = "en-Us"
But the calender text is shown in Finnish culture.
I need to keep the Text(Translations) based on CurrentUICulture and Text Format based on CurrentCulture.
Can you please suggest how can it be done for it?
That is not possible. The Calendar control only reacts to the CurrentCulture value. CurrentUICulture is used by the ResourceManager to load up different strings, images etc. used in the UI, but that is not where the day/month names are stored. They are part of the .NET framework itself. To get the functionality you want you will have to write your own implementation of the DatePicker and/or TimePicker controls. Perhaps you could download the code for the Silverlight Toolkit and use that as a base for your own implementation. What you are looking for is basically a way of overriding the names of months and days manually. Maybe it is even possible to extend the controls and add that functionality on top, but I doubt it.
I'm using WPF with MVVM implementation, and have a WPF DatePicker control. I've set the default date on my property using DateTime.Now, but I would like to disable all the Dates on the DatePicker control that fall before the current date so that the User cannot select any earlier dates.
I've tried setting this in xaml using FallbackValue={x:Static sys:DateTime.Now} in my SelectedDate property, and {x:Static sys:DateTime.Now} in most of the other properties (from another source) but the dates before the current dates are still displayed and still selectable.
Is there an easy way to accomplish this?
Maybe you're looking BlackoutDates property?
Here is more info of using the DatePicker control (including BlackoutDates):
WPF Toolkit: Calendar & DatePicker Walkthrough
For example if you want to set your blackout dates from 1/1/2000 to present day you can do:
<Calendar.BlackoutDates>
<CalendarDateRange Start="1/1/2000" End="{x:Static System:DateTime.Today}" />
</Calendar.BlackoutDates>
Where System namespace is defined as
xmlns:System="clr-namespace:System;assembly=mscorlib"
You can use DisplayDateStart and DisplayDateEnd properties to select what dates should be displayed in the control or if you want something more complex you can use BlackOutDates to select exactly what dates you don't want to be selectable.
CalendarDateRange cdr = new CalendarDateRange(DateTime.MinValue, DateTime.Today);
myCalendar.BlackoutDates.Add(cdr);
You can use
MyDatePicker.BlackoutDates.AddDatesInPast();
See https://msdn.microsoft.com/en-us/library/system.windows.controls.calendarblackoutdatescollection.adddatesinpast(v=vs.110).aspx
From this article http://msdn.microsoft.com/en-us/magazine/dd882520.aspx I wanted to create a list of selected days like he did. Except my list is not static and putting it in the converter seems smelly. Has anyone done something similar with the WPF toolkit calendar control? Or are we trying to use this control for something more than what it is intended?
Use a MultiValueConverter which takes a DateTime and a list of special days.
I'm getting some very strange date formatting issues in my Silverlight application. My local culture is set to UK, yet I am consistently seeing US dates popping up all over the place. I can easily hardcode these to UK format in specific loactions using:
<UserControl ... Language="en-GB"...>
But as I'm sure you'd all agree this is a terrible thing to do.
I have tried setting the Lanaguage to en-GB in the main application and this has partial success. I have also tried Justin Angels suggestion (posted here: How to change date format in Silverlight DatePicker control?), again only partial success.
An example of the issue can be seen here:
http://lh3.ggpht.com/%5FL9TmtwXFtew/Sw5aVZJfG1I/AAAAAAAAGkI/6jYnsB91HjI/image%5Fthumb%5B1%5D.png http://lh3.ggpht.com/%5FL9TmtwXFtew/Sw5aVZJfG1I/AAAAAAAAGkI/6jYnsB91HjI/image%5Fthumb%5B1%5D.png
The datagrid on the parent page shows UK formatting, whilst the information in the ChildWindow shows US formatting ...grrrr
Anyone have a definitive solution for solving this across a whole application?
Thanks,
Mark
You can data bind Language property of the root visual element. Take a look at my question here:
How to switch UI Culture of data binding on the fly in Silverlight
Can you not use the SelectedDateFormat property of the datepicker? If you want to do this once could you not create your own usercontrol that derives from the original with this value preset, then use your derived control throughout your app?
Kindness,
Dan
Shot in the dark, but does changing the browser's Language Preference make a differnence? I.e. in IE Tools-->Internet Options-->Languages.
HTH
Mark
You can set the date format for your entire application in the application start up event as follows.This will override any regional settings on the users machine
Thread.CurrentThread.CurrentCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = dd/MM/yyyy";