简体   繁体   中英

Calendar Control - Display Quarters

I'm trying to put together a calendar control(WPF) which will only show dates from a collection of dates which are quarterly in nature.

For example my collection(a list of Datetime objects) of dates will be as follows

31/Mar/2012

31/Dec/2012

30/Sep/2012

30/Jun/2012

30/Mar/2012

Now I can use the calendar control and set it's display mode to Year just to show the year-month view, but how can I set the control to blackout the months which are not available in the above collection and only show the months available in the collection?

Please note that the question has 2 parts:

  1. how do I blackout a month while display mode of the calendar is set to year?
  2. how do i blackout the months which are not part of the collection?

Can you please help?

Simply find the minimum and maximum dates and then do this:

calendarControl.BlackoutDates.Add(new CalendarDateRange(minDate, maxDate));

further you can do ranges, so let's say it's not that straight forward and you need multiple ranges (though it doesn't look like it from your question) then you could do this:

calendarControl.BlackoutDates.Add(new CalendarDateRange(rangeStart, rangeEnd));

further you can even black out a specific date like this:

calendarControl.BlackoutDates.Add(new CalendarDateRange(blackoutDate));

so in your case it might be easiest to just black out certain dates. Just loop through the list and leverage the last code example I gave you.

You could try something like this:

public void BlackOutDates(startDate, endDate, periodInDays)
{
    while(startDate < endDate)
    {
        calender.BlackoutDates.Add(new CalendarDateRange(startDate, startDate.AddDays(periodInDays));
        startDate = startDate.AddDays(periodInDays+1);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM