Home > Enterprise >  How to set usual background when IsEnabled of control is false
How to set usual background when IsEnabled of control is false

Time:12-23

I don't want to change user my Calendar, so I set IsEnabled = false. But I don't like its background: disabled

I want to see them as usual background:

notdisable

Is there any possibilities?

CodePudding user response:

I recently had similar problems with disabling wpf controls and the resulting style. For me setting IsHitTestVisible = False, was the best option. But not 100% sure if this only disables mouse interactions or also the predefined keyboard controls.

CodePudding user response:

You should use the Calendar.BlackoutDates property to disable particular dates or date ranges.

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>

Visit the API reference for the full example: Calendar.BlackoutDates Property.
Read this article for further knowledge on how to handle the Calendar control: Calendar

  • Related