Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Calendar: Boldface specified dates?

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.

like image 389
David Veeneman Avatar asked Aug 17 '10 17:08

David Veeneman


2 Answers

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));
}
like image 94
XstreamINsanity Avatar answered Nov 15 '22 11:11

XstreamINsanity


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.

like image 31
David Veeneman Avatar answered Nov 15 '22 11:11

David Veeneman