简体   繁体   English

日历控件-显示季度

[英]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. 我正在尝试将一个日历控件(WPF)放在一起,该控件仅显示本质上每季度一次的日期集合中的日期。

For example my collection(a list of Datetime objects) of dates will be as follows 例如,我的日期集合(Datetime对象的列表)如下

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? 现在,我可以使用日历控件并将其显示模式设置为Year,以仅显示年月视图,但是如何将控件设置为不显示上述集合中不可用的月份,而仅显示日历中可用的月份。采集?

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);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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