In our current Project we are using the WPFToolkit DateTimePicker, Its having lot of events that we are using instead of WPF DatePicker. But there is one problem with this control. We cannot disabled the previous dates. We don't want the user to select the previous dates in the calendar, Suppose the DatePicker name is ExDatePicker but we cannot write ExDatePicker.MinDate = DateTime.Today or DateTime.Now in the ExDatePicker.Loaded method.
Can we do anything else to disable the previous dates? In WPF DatePicker we have one option dateTimePicker.MinDate = DateTime.Now;
I am missing this feature very much. Help or suggestions please.
If you are using an older version of the WPFToolkit you have to update because the fixed this issue some month ago: Add Mininum/Maximum properties in DateTimeUpDown
Related
I have a DatePicker which displays the date only and a separate TextBox that displays the time. Both elements use TwoWay binding.
My issue is that when ever I adjust the date using the DatePicker, my time resets to 00:00. Is there a way to disable this behavior and leave the TimeOfDay alone? I can't seem to find an answer anywhere.
I know I could grab the time with a GotFocus event and then manually restore, but it seems messy.
The DatePicker and TextBox should be bound to two different source properties, a DateTime? and a TimeSpan respectively.
The built-in DatePicker control selects only a date without any specific time so it makes no sense to try to display the time of the selected date in a TextBox.
Is there a way to add a new custom Display Mode to the WPF Calendar control nad how can it be done?
First, I want to describe my problem more in detail.
In my application I need a date (and time) picker in one control to select first a single date and then the time for this date.
The control (as it is) has three display modes which are Decade (showing 12 Years), Month (showing the 12 months of the selected year) and Days (showing the days of the selected month).
What I want to do is, adding another display mode "Hours" which then will show the 24 hours of the selected day.
So there are many problems.
How to add this view?
How to avoid closing the popup after selecting a date? -> it should switch to hours instead and close after selecting the hour
How to add the arrows in the last view to show 12 hours and the halfs on page one of the hours view
How to bind all this to the underlying datetime object which I am interested in at most because it contains what the user selected ;-)
Hope the problem is clear. If there is no direct way to add a view to existing Calendar control than any idea how to solve this would be appreciated.
You could try the Extended WPF toolkit, if you are looking for a out-of-the-box solution. It does not do exactly what you are describing, but it does allow you to select a time in addition to a date.
But if it's not enough, I am pretty sure you will have to make a completely new component. In most cases, a restyling of a component is sufficient to add new features, but in this case, you would most likely have to rewrite it from scratch.
As a workaround, we made a separate hour selection component, which were displayed on the side of the calendar. It's simpler than to rewrite the whole thing anew.
I have history window with date picker but there’s some days without any record in DataBase, I want to disable this days in the datepicker.
Any ideas please.
Thank you
You can use the DayRender event handler for disabling the dates in the datepicker. Refer this sample site to know.
Have a look at the DatePicker.BlackoutDates Property. Dates in this collection will appear as disabled on the drop-down calendar.
I've been working in silverlight to do a date-oriented application. I started off with changing the calendar template to contain a listbox on every date, and I created a listbox containing simple items.
I implemented an easy drag drop on both those elements, so now I can drag from the listbox containing the items to the listbox on a date and have an event.
Downside is: In the event, I don't know which date it was dropped to.
How can I figure this out?
Please note: The date dropped to is not necessarily the date currently selected...
As it turns out, using a different drag drop implementation (http://silverlightdragdrop.codeplex.com/) got me to the date relatively easy:
DateTime datetime = (DateTime)((DropTarget)sender).DataContext;
All thanks for viewing and thinking...
I am making a program that will help people "book" orders for a department in C#. They need to be able to choose multiple dates in different months.
I would prefer to have it so they can click a date, and then shift click another one to select all dates between those two, and control clicking as well, to do single selection/deselection. They have to be able to move between months while still retaining all the dates they clicked for the previous month, this way they can overview the dates they've selected to make it easier.
What is the best way to do this? Should I use Visual Studio's default month calendar or is there a more flexible one that exists?
You can make it work by detecting clicks on dates and then add or remove the clicked date from the bolded dates. Implement the MonthCalendar's MouseDown event:
private void monthCalendar1_MouseDown(object sender, MouseEventArgs e) {
MonthCalendar.HitTestInfo info = monthCalendar1.HitTest(e.Location);
if (info.HitArea == MonthCalendar.HitArea.Date) {
if (monthCalendar1.BoldedDates.Contains(info.Time))
monthCalendar1.RemoveBoldedDate(info.Time);
else
monthCalendar1.AddBoldedDate(info.Time);
monthCalendar1.UpdateBoldedDates();
}
}
Just one problem with this, it flickers like a cheap motel. No fix for that.
The WinForms MonthCalendar supports selection of a Range, from Start to End but not the (de)selection of individual dates with Ctrl. So it seems it does not meet your requirements.
Just a quick note: If you resize the MonthCalendar it will show more months. Together with nobugz' answer that might give you a working solution.
Assuming that you are using WPF...
I would recommend that you create a simple ListBox and bind the ItemsSource property to the Calendar's SelectedDates property. As the user selects and deselects days from the Calendar, they will be added to or removed from the list.
In addition, you could create a DateSpan class and a ValueConverter to group dates in a series into your DateSpan class. You could then apply the converter to the SelectedDates property so that when the user uses Shift-Select, they will see a date span rather than a bunch of dates (assuming that's a bad thing). The logic wouldn't be too complex.
There are plenty of third-party tools out there, but no matter which control you use the core problem will remain: you want the user to be aware of all selected items, but you don't want to show every single month that contains a selected day at the same time. The best answer I can think of would be a list.