Articles in this section
Category / Section

How to customize the header of the UWP Calendar?

1 min read

You can customize the header of the SfCalendar by using the HeaderTemplate property. This article explains how to customize the header of the SfCalendar to display only the month.

Customizing the header of the SfCalendar:

  Define the converter as a Resource. Create a TextBlock and set it as the HeaderTemplate of the SfCalendar. Bind the DisplayDate of the SfCalendar to the Text property of the TextBlock with reference to the converter.

 

<Page.Resources>
      <local:CalendarHeaderFormater x:Key="HeaderFormater"/>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
  <Input:SfCalendar x:Name="calendar" ShowNavigationButton="True" Height="300" 
                    Width="500">
    <Input:SfCalendar.HeaderTemplate>
     <DataTemplate>
        <TextBlock Text="{Binding ElementName=calendar, Path=DisplayDate, 
                          Converter={StaticResource HeaderFormater}}" FontSize="22" 
                          Margin="0 5" HorizontalAlignment="Center"/>
     </DataTemplate>
    </Input:SfCalendar.HeaderTemplate>
  </Input:SfCalendar>
 </Grid>

 

 Create a UWP application and add the SfCalendar to it. Define a converter class with reference to the IValueConverter interface. In the Convert method, return the date in the month format.

 

    public class CalendarHeaderFormater : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, 
                              string language)
        {
            
            DateTime data;
            CultureInfo currentculture = parameter as CultureInfo;
            bool isvalid = DateTime.TryParse(value.ToString(), out data);
            if (isvalid)
            {
                return data.ToString("MMMM", currentculture);
            }
            else
            {
                return null;
            }
        }
    }

 

 

 

The following screenshot displays the output of the above code.

 



Conclusion

I hope you enjoyed learning about how to customize the header of the UWP Calendar.

You can refer to our UWP Calendar feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our UWP Calendar example to understand how to create and manipulate data.

For current customers, you can check out our Xamarin components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied