1
votes

I need a year calendar in WPF, that is, 12 Calendars (one per month) in one single control. This could be done by creating a new control with 12 calendars and disabling the next/previous buttons... etc.

My main problem is that, I need to allow the user to select multiple range dates even these dates are of two diferent months. For instance, when the user clicks on 20th January, then hold shift and then click on 10th February, dates between 20th January an 10 th February must be selected.

Is it possible?

1
Of course it is, but writing it up will be a pain and you'll have to do lot of logic checks ... Why not have a AddRange method where you'll ask for start date and end date, and add them?Noctis

1 Answers

2
votes

Anything is possible, given enough time and effort, however what you are suggesting is likely to take up a lot of your time in order to allow the user to select date ranges in this way.

(In this discussion I am going to assume that you always have a fixed year of 365 days to select from, even if that might be Nov 2013 - Oct 2014. Considering a dynamic range would make everything even more challenging)

If you have multiple calendars they won't know how to keep selected range in sync. If you were building this, the first thing to tackle would be producing a readonly year calendar so that given a year, you highlight the selcted portion across all calendars. After that you would tackle simple interactions, such as if the user shift-selects in one calendar, then you can reuse your work in displaying that readonly range you did above. However if you want your user to be able to drag a selection across multiple calendars, you are going to find it much harder. Passing the state of the mouse across the calendars will require a good bit of synchronisation.

At this point you might find that the work involved in having the calendars could be better spent either getting a control which can already handle this such as devexpress, syncfusion, etc, or even building your own.

Personally I'd use two date drop downs to precisely pick the dates for start and stop, and then have a readonly representation of the range over the year. If that isn't sufficient, then have a look at using a dual slider control (search WPF dual slider for commercial and open source options). This would then give you a simple way to drag start or end dates over the year.

You could simply use your readonly view from above or even just a simple border to show the range. Bind the borders Margin.Left to the number of days since the start of the year / 365 * totalWidth and Bind its Width to the number of days between the two dates /365 * totalWidth.

Finally you could simply keep your readonly calendars as a the only visible component on view and pair them up with other things to do the selection when the user interacts with them. Maybe pop up the pair of drop downs when the mouse is clicked over the calendars.