Xamarin.iOS Documentation | ComponentOne
Controls / Calendar / Features / Custom Selection
In This Topic
    Custom Selection
    In This Topic

    You can customize the default behavior of the C1Calendar control to select specific dates. For instance, consider a scenario where you wish to select only the weekdays on tapping two dates in different workweeks. For this, you simply need to subscribe the SelectionChanging event and apply selection condition in the handler.

    The following image shows a C1Calendar that only selects weekdays and deselect weekends on tapping two different dates in different workweeks.

    The following code example shows how to customize selection in C1Calendar control in C#. The example uses the sample created in the Quick Start.

    1. Replace the content of the ViewController.cs file with the code given below.
      C#
      Copy Code
      using C1.iOS.Calendar;
      using System;
      using UIKit;
      
      namespace CalendariOS
      {
          public partial class ViewController : UIViewController
          {
              public ViewController(IntPtr handle) : base(handle)
              {
              }
      
              public override void ViewDidLoad()
              {
                  base.ViewDidLoad();
                  Calendar.SelectionChanging += OnSelectionChanging;
              }
              public override void ViewDidUnload()
              {
                  base.ViewDidUnload();
                  Calendar.SelectionChanging -= OnSelectionChanging;
              }
      
              private void OnSelectionChanging(object sender, CalendarSelectionChangingEventArgs e)
              {
                  foreach (var date in e.SelectedDates.ToArray())
                  {
                      if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
                          e.SelectedDates.Remove(date);
                  }
              }
      
          }
      }