WPF Calendar: Boldface specified dates?

前端 未结 2 457
被撕碎了的回忆
被撕碎了的回忆 2021-01-12 10:49

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 f

相关标签:
2条回答
  • 2021-01-12 11:20

    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));
    }
    
    0 讨论(0)
  • 2021-01-12 11:21

    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.

    0 讨论(0)
提交回复
热议问题