简体   繁体   中英

WPF Calendar disable date selection

Hi guys i want a way to disable date selection in a WPF calendar.

i tried the disabled property but i want to navigate from dates, i have selected dates by default and dont want the user to be able to select dates.

This is my calendar code:

<Calendar x:Name="show_Calendar" IsTodayHighlighted="False" SelectionMode="MultipleRange" />

and i select dates like this:

SelectedDatesCollection dates = new SelectedDatesCollection(show_Calendar);
foreach (var item in TaskManagerClass.revisionesTarea(tareaActiva.Id))
{
   if (item.DiaRevision.HasValue)
     dates.Add(item.DiaRevision.Value);
}

I want the user to be able to navigate between months but cannot select dates from the calendar.

You may disable the selection of dates by setting the IsHitTestVisible property of the CalendarDayButton to false using a Style :

<Calendar x:Name="show_Calendar" IsTodayHighlighted="False" SelectionMode="MultipleRange">
    <Calendar.CalendarDayButtonStyle>
        <Style TargetType="CalendarDayButton">
            <Setter Property="IsHitTestVisible" Value="False" />
        </Style>
    </Calendar.CalendarDayButtonStyle>
</Calendar>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM