开发者

How to find the dates shown in a Silverlight Calendar control?

I have a Silverlight application that contains a calendar control. I'm wanting to 'black out' days for which we have no data available, using the BlackoutDates property.

So I'm looking for a simple way to find all the dates that are currently visible (assuming a Month view, for now). I can use a brute force method, say taking the first day of the month minus seven days to the last开发者_如何学Go day of the month plus seven days, but can anyone suggest a cleaner method?


How expensive an operation is it for you to find out which dates have no data?

If it's cheap just set the BlackoutDates property with all the dates for the current visible month and the months either side, let the calendar worry about which are visible and which are not.


Another solution is to react to the SelectedDatesChanged event to reject specific date selections, such as dates that fall on a weekend:

private void Calendar_SelectedDatesChanged (object sender, CalendarDateChangedEventArgs e)
{
// Check all the newly added items.
foreach (DateTime selectedDate in e.AddedItems)
{
if ((selectedDate.DayOfWeek == DayOfWeek.Saturday) || (selectedDate.DayOfWeek == DayOfWeek.Sunday))
{
lblError.Text = "Weekends are not allowed";
// Remove the selected date. ((Calendar)sender).SelectedDates.Remove(selectedDate);
}
}
}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜