Res
Res

Reputation: 115

Change background color of today in calendarview UWP

How can I change the color of today's background in CalendarView?

CalendarView

Always thank you in advance..!

Upvotes: 1

Views: 968

Answers (2)

foson
foson

Reputation: 10227

The style key you need to override to customize the color used when IsTodayHighlighted="True" is SystemControlHighlightAccentBrush

<CalendarView>
  <CalendarView.Resources>
    <SolidColorBrush x:Key="SystemControlHighlightAccentBrush" Color="Green" />
  </CalendarView.Resources>
</CalendarView>

Upvotes: 5

iam.Carrot
iam.Carrot

Reputation: 5276

You can achieve this with not much of an effort using c#. And to be honest it's much better than writing up a style for such a trivial thing. Below is how you do it:

  1. Subscribe to the CalendarViewDayItemChanging event of the CalendarView
  2. Write up the code to change the color, something like below:

  private void CalendarView_CalendarViewDayItemChanging(CalendarView sender, CalendarViewDayItemChangingEventArgs args)
  {
      if (args.Item.Date.Date.Equals(DateTime.Now.Date))
          args.Item.Background = new SolidColorBrush(Colors.Yellow);
  }

While your XAML declaration looks like below:

<CalendarView CalendarViewDayItemChanging="CalendarView_CalendarViewDayItemChanging"/>

Upvotes: 2

Related Questions