views:

253

answers:

2

Hi all,

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 day of the month plus seven days, but can anyone suggest a cleaner method?

+1  A: 

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.

Graeme Bradbury
A: 

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

Dmytro Laptin