This section describes how to add a Calendar control to your Xamarin application and select a date on the calendar at runtime. This topic comprises of two steps:
The following image shows how the Calendar appears after completing the above steps.
Complete the following steps to initialize a Calendar control in C# or XAML.
C# |
Copy Code
|
---|---|
using Xamarin.Forms; using C1.Xamarin.Forms.Calendar; |
C# |
Copy Code
|
---|---|
public static C1Calendar ReturnMyControl() { C1Calendar calendar = new C1Calendar(); calendar.MaxSelectionCount = -1; calendar.HorizontalOptions = LayoutOptions.FillandExpand; calendar.FontSize = 20; return calendar; } |
XAML |
Copy Code
|
---|---|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:c1="clr-namespace:C1.Xamarin.Forms.Calendar;assembly=C1.Xamarin.Forms.Calendar" x:Class="CalendarQuickStart.QuickStart" Padding="20"> </ContentPage> |
XAML |
Copy Code
|
---|---|
<Grid> <Label Text="{Binding MainText}" HorizontalOptions="Center" Font="Large" /> <c1:C1Calendar x:Name="calendar" MaxSelectionCount="-1"/> </Grid> |
C# |
Copy Code
|
---|---|
public App() { // The root page of your application MainPage = new ContentPage { Content = QuickStart.ReturnMyControl() }; } |
C# |
Copy Code
|
---|---|
public App() { // The root page of your application MainPage = new QuickStart(); } |
C# |
Copy Code
|
---|---|
C1.Xamarin.Forms.Calendar.Platform.iOS.C1CalendarRenderer.Init(); |
C# |
Copy Code
|
---|---|
C1.Xamarin.Forms.Calendar.Platform.UWP.C1CalendarRenderer.Init(); |
(Optional) In case you compile your UWP application in Release mode, you need to explicitly add the following code to the OnLaunched method in your App.xaml.cs to include the correct assemblies with your application.
C# |
Copy Code
|
---|---|
var assembliesToInclude = new List<Assembly>(); assembliesToInclude.Add(typeof(C1.Xamarin.Forms.Calendar.Platform.UWP.C1CalendarRenderer) .GetTypeInfo().Assembly); assembliesToInclude.Add(typeof(C1.UWP.Calendar.C1Calendar).GetTypeInfo().Assembly); Xamarin.Forms.Forms.Init(e, assembliesToInclude); |