当控件的 IsEnabled 为 false 时如何设置通常的背景

How to set usual background when IsEnabled of control is false

我不想更改用户我的日历,所以我设置了 IsEnabled = false。但我不喜欢它的背景:

我想像往常一样看到它们的背景:

有没有可能?

我最近在禁用 wpf 控件和生成的样式方面遇到了类似的问题。对我来说,设置 IsHitTestVisible = False 是最好的选择。但不能 100% 确定这是否只会禁用鼠标交互或预定义的键盘控件。

您应该使用 Calendar.BlackoutDates 属性 来禁用特定日期或日期范围。

C#

Calendar calendarWithBlackoutDates = new Calendar();

// Add the dates that are not selectable.
calendarWithBlackoutDates.BlackoutDates.Add(
  new CalendarDateRange(new DateTime(2009, 1, 2), new DateTime(2009, 1, 4)));

XAML

<Calendar Margin="20" SelectionMode="MultipleRange"  
          IsTodayHighlighted="false" 
          DisplayDate="1/1/2009"
          DisplayDateEnd="1/31/2009"
          xmlns:sys="clr-namespace:System;assembly=mscorlib">

  <Calendar.BlackoutDates>
    <CalendarDateRange Start="1/2/2009" End="1/4/2009"/>
  </Calendar.BlackoutDates>
</Calendar>

访问 API 参考以获取完整示例:Calendar.BlackoutDates Property
阅读这篇文章以进一步了解如何处理 Calendar 控件:Calendar