views:

100

answers:

2

I am creating a window that uses a WPF calendar to browse documents created on specified dates during the month shown. When the calendar changes month, I search a database for all documents created during that month, which I use to create a list of dates during the month that have documents.

In the Calendar control, I want to boldface those dates that have documents, in the same manner that Outlook boldfaces dates that have appointments.

So, here's my question: How do I boldface a specific date in the Calendar control's month view? Thanks for your help.

+3  A: 

This may help. http://www.c-sharpcorner.com/UploadFile/mahesh/539/Default.aspx The "Selected Date and Selected Dates" area will show you how to select them, and further down it can show you how to format your calendar. That is, if you're using the same calendar which I hope you are. Hope this helps.

Selected Date and Selected Dates

SelectedDate property represents the current selected date. If multiple date selection is true, then SelectedDates property represents all selected dates in a Calendar. The following code snippet sets the SelectedDates in XAML at design-time.

<Calendar Name="MonthlyCalendar" 
    SelectionMode="MultipleRange"  
    DisplayDate="3/5/2010"
    DisplayDateStart="3/1/2010"
    DisplayDateEnd="3/31/2010"
    FirstDayOfWeek="Tuesday"
    IsTodayHighlighted="True" 
    xmlns:sys="clr-namespace:System;assembly=mscorlib" Margin="15,39,88,19">

    <Calendar.SelectedDates>
        <sys:DateTime>3/5/2010</sys:DateTime>
        <sys:DateTime>3/15/2010</sys:DateTime>
        <sys:DateTime>3/25/2010</sys:DateTime>
     </Calendar.SelectedDates>
</Calendar>

The selected dates in a Calendar looks like Figure 8 where you can see March 5th, 15th, and 25th have a light blue background and represents the selected dates.

The following code snippet sets the SelectedDates property in WPF at run-time.

private void AddSelectedDates()
{
    MonthlyCalendar.SelectedDates.Add(new DateTime(2010, 3, 5));
    MonthlyCalendar.SelectedDates.Add(new DateTime(2010, 3, 15));
    MonthlyCalendar.SelectedDates.Add(new DateTime(2010, 3, 25));
}
XstreamINsanity
Thanks! Accepted and +1 for code in both WPF and XAML--very helpful.
David Veeneman
No problem, glad to help.
XstreamINsanity
Sorry--had to withdraw the acceptance. That solution selects the dates. All I want to do is boldface them. I'll click on a date to select it and show the Notes created on that date. Left the +1 for helpful code.
David Veeneman
In the link that I provided there is formatting examples. Not sure if that will help.
XstreamINsanity
This also gives a good explanation of styling the calendar in general. http://msdn.microsoft.com/en-us/magazine/dd882520.aspx
XstreamINsanity
This problem is going to require a custom control derived from the WPF Calendar. I'll write it up at CodeProject when I am done and post a link to the article here.
David Veeneman
A: 

It turns out that boldfacing is hard-coded in several places, so I changed to date highlighting instead. I wrote a custom control that has a HighlightedDates list; adding a date to the list highlights the date and provides an optional tool tip for the date with whatever content the host app chooses.

I have written a CodeProject article titled Extending the WPF Calendar. The article includes the control and explains how I built it.

David Veeneman