You can also customize the default behavior of the C1Calendar control to select specific dates. For instance, consider a scenario where you wish to select only weekdays on tapping two dates in different workweeks. For this, you simply need to subscribe the getSelectionChanging event and apply selection condition in the handler.
The following image shows a Xamarin Calendar that selects weekdays and deselects weekends on tapping two different dates in different workweeks.
The following code example demonstrates how customize selection in C#. The following code example uses the sample created in the Quick Start.
C# |
Copy Code |
---|---|
using Android.App; using Android.Widget; using Android.OS; using C1.Android.Calendar; using System; using Android.Views; |
C# |
Copy Code |
---|---|
public class MainActivity : Activity { C1Calendar calendar; protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); calendar = FindViewById<C1Calendar>(Resource.Id.calendar); 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); } } public override bool OnOptionsItemSelected(IMenuItem item) { if (item.ItemId == global::Android.Resource.Id.Home) { Finish(); return true; } else { return base.OnOptionsItemSelected(item); } } |