Localize and change format in WinUI Calendar (SfCalendar)

2 Aug 20214 minutes to read

This section describes how to localize Calendar control using CalendarIdentifier and Language properties and to change the display formats.

Types of Calendar

The Calendar control supports different type of calendars such as Gregorian, Julian, Hebrew, etc. You can change the calendar type by using CalendarIdentifier property. The default value of CalendarIdentifier property is GregorianCalendar.

You can select the required CalendarIdentifier value from below types.

  • JulianCalendar
  • GregorianCalendar
  • HebrewCalendar
  • HijriCalendar
  • KoreanCalendar
  • TaiwanCalendar
  • ThaiCalendar
  • UmAlQuraCalendar
  • PersianCalendar

NOTE

Japanese and Lunar type calendars are not supported in Calendar control.

NOTE

When CalendarIdentifier and FlowDirection properties are set, FlowDirection property is given higher precedence.

NOTE

Calendar control updates the flow direction visually based on the CalendarIdentifier property value.

<calendar:SfCalendar CalendarIdentifier="HebrewCalendar"
                     x:Name="sfCalendar"/>
SfCalendar sfCalendar = new SfCalendar();
sfCalendar.CalendarIdentifier = "HebrewCalendar";

WinUI Hebrew Calendar-Calendar Identifier

NOTE

Download demo application from GitHub

Change the language

You can localize the calendar using the Language property. The default value of Language property is en-US.

<calendar:SfCalendar Language="fr-FR"
                     x:Name="sfCalendar"/>
SfCalendar sfCalendar = new SfCalendar();
sfCalendar.Language = "fr-FR";

WinUI French Calendar

NOTE

Download demo application from GitHub

First day of week

By default, Sunday is shown as the first day of the week. If you want to change the first day of week, use the FirstDayOfWeek property value.

<calendar:SfCalendar x:Name="sfCalendar" 
                     FirstDayOfWeek="Monday"/>
SfCalendar sfCalendar = new SfCalendar();
sfCalendar.FirstDayOfWeek = DayOfWeek.Monday;

WinUI Calendar First Day of Week

NOTE

Download demo application from GitHub

Change flow direction

You can change the flow direction of the Calendar layout from right to left by setting the FlowDirection property value as RightToLeft. The default value of FlowDirection property is LeftToRight.

NOTE

When CalendarIdentifier and FlowDirection properties are set, FlowDirection property is given higher precedence.

<calendar:SfCalendar FlowDirection="RightToLeft" 
                     x:Name="sfCalendar"/>
SfCalendar sfCalendar = new SfCalendar();
sfCalendar.FlowDirection = FlowDirection.RightToLeft;

WinUI Calendar Right-to-Left

NOTE

Download demo application from GitHub

Change date display format

You can use different date formats such as abbreviated or full name for a day, month, week names or header name of month and year by using the DayFormat, MonthFormat, DayOfWeekFormat and MonthHeaderFormat properties.

NOTE

Refer DateTimeFormatter page to get more date formatting.

<calendar:SfCalendar DayFormat="{}{day.integer(2)}"
                     MonthFormat="{}{month.full}"
                     DayOfWeekFormat="{}{dayofweek.abbreviated(3)}"
                     MonthHeaderFormat="{}{month.abbreviated} {year.abbreviated}‎"
                     x:Name="sfCalendar"/>
SfCalendar sfCalendar = new SfCalendar();
sfCalendar.DayFormat = "{day.integer(2)}";
sfCalendar.MonthFormat = "{month.full}";
sfCalendar.DayOfWeekFormat = "{dayofweek.abbreviated(3)}";
sfCalendar.MonthHeaderFormat = "{month.abbreviated} {year.abbreviated}‎";

WinUI Calendar Date Formatting

NOTE

Download demo application from GitHub

Number of weeks in a view

If you want to increase or decrease the number of weeks shown in a month view, use the NumberOfWeeksInView property. The default value of NumberOfWeeksInView property is 6.

<calendar:SfCalendar NumberOfWeeksInView="3"
                     x:Name="sfCalendar"/>
SfCalendar sfCalendar = new SfCalendar();
sfCalendar.NumberOfWeeksInView = 3;

WinUI Calendar Showing Only Limited Weeks in View

NOTE

Download demo application from GitHub