CalendarView In Xamarin.Forms

Introduction

In this tutorial, we will learn how to use CalendarView in Xamarin.Forms. This plugin will help more when we are creating a mobile app for the attendance management system.
This Calendar Control is an awesome plugin created by Rebecca and is open-sourced on GitHub. This control offers
To know more about it, we will skip into the coding part without delay.

Steps

I have split this part into 3 steps as in the following.
Step 1
Creating new Xamarin.Forms projects.
Step 2
Setting up the plugin for Xamarin.Forms application.
Step 3
Implementing CalendarView in Xamarin.Forms.
Step 1 - Creating new Xamarin.Forms Projects
Step 2 - Setting up the plugin for Xamarin.Forms Application
Step 3 - Implementing CalendarView in Xamarin.Forms

Full Code

MainPage.xaml
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  4. xmlns:d="http://xamarin.com/schemas/2014/forms/design"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. xmlns:controls="clr-namespace:XamForms.Controls;assembly=XamForms.Controls.Calendar"
  7. xmlns:viewmodels="clr-namespace:CalendarSample"
  8. mc:Ignorable="d"
  9. x:DataType="viewmodels:MainPageModel"
  10. x:Class="CalendarSample.MainPage">
  11. <StackLayout>
  12. <controls:Calendar Padding="10,0,10,0"
  13. SelectedBorderWidth="4"
  14. DisabledBorderColor="Black"
  15. ShowNumberOfWeek="false"
  16. StartDay="Monday"
  17. TitleLabelTextColor="Purple"
  18. TitleLeftArrowTextColor="Blue"
  19. SelectedDate="{Binding Date}"
  20. SpecialDates="{Binding Attendances}"
  21. DateCommand="{Binding DateChosen}"/>
  22. </StackLayout>
  23. </ContentPage>
MainPageModel.cs
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using Xamarin.Forms;
  4. namespace CalendarSample
  5. {
  6. public class MainPageModel : BindableObject
  7. {
  8. private DateTime? _date;
  9. public DateTime? Date
  10. {
  11. get
  12. {
  13. return _date;
  14. }
  15. set
  16. {
  17. _date = value;
  18. OnPropertyChanged(nameof(Date));
  19. }
  20. }
  21. private ObservableCollection<XamForms.Controls.SpecialDate> attendances;
  22. public ObservableCollection<XamForms.Controls.SpecialDate> Attendances
  23. {
  24. get
  25. {
  26. return attendances;
  27. }
  28. set
  29. {
  30. attendances = value;
  31. OnPropertyChanged(nameof(Attendances));
  32. }
  33. }
  34. public Command DateChosen
  35. {
  36. get
  37. {
  38. return new Command((obj) =>
  39. {
  40. System.Diagnostics.Debug.WriteLine(obj as DateTime?);
  41. });
  42. }
  43. }
  44. }
  45. }
Reference
Calendar Control in Xamarin.Forms
Download Code
You can download the code from GitHub. If you have doubts, feel free to post a comment. If you like this article and it is useful to you, do like, share the article & star the repository on GitHub.