Xuni Product Documentation - Xamarin.Forms
Quick Start: Display a Xuni Calendar Control

This section describes how to add a Xuni Calendar control to your android application and select a date on the calendar at runtime. This topic comprises of two steps:

The following image shows how the Xuni Calendar appears after completing the above steps.

Step 1: Add a Calendar Control

Complete the following steps to initialize a Calendar control in C# or XAML.

In Code

  1. Add a new class (say QuickStart.cs) to your Portable or Shared project and include Xuni Calendar and Xamarin references stated below.
    C#
    Copy Code
    using Xamarin.Forms;
    using Xuni.Forms.Calendar;
  2. Instantiate a Calendar control in a new method ReturnMyControl() as illustrated in the code below.
    C#
    Copy Code
    public static XuniCalendar ReturnMyControl()
       {
          XuniCalendar calendar = new XuniCalendar();
          calendar.MaxSelectionCount = -1;
          calendar.HorizontalOptions = Xamarin.Forms.LayoutOptions.Center;
          calendar.FontSize = 30;
          return calendar;
       }

In XAML

  1. Add a new Forms XAML Page (say QuickStart.xaml) to your Portable or Shared project and modify the <ContentPage> tag to include the Xuni references as illustrated below.
    XAML
    Copy Code
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:xuni="clr-namespace:Xuni.Forms.Calendar;assembly=Xuni.Forms.Calendar"
    x:Class="CalendarQuickStart.QuickStart"
    Padding="20">
  2. Initialize a Calendar control by adding the following markup to the control between the <ContentPage></ContentPage> tags inside the <Grid></Grid> tags as illustrated below.
    XAML
    Copy Code
    <Grid>
        <Label Text="{Binding MainText}" HorizontalOptions="Center" Font="Large" />
        <xuni:XuniCalendar x:Name="calendar" MaxSelectionCount="-1" />
      </Grid>
    </ContentPage>

Step 3: Run the Project

  1. In the Solution Explorer, double-click App.cs file to open it.
  2. Complete the following steps to display the Calendar control.
    • To return a C# class: In the class constructor App(), set a new ContentPage as the MainPage and assign the control to the ContentPage's Content by invoking the ReturnMyControl() method in Step 2 above. The following code shows the class constructor App() after completing this step.
      C#
      Copy Code
      public App()
        {
           // The root page of your application
           MainPage = new ContentPage
             {
               Content = QuickStart.ReturnMyControl()
              };
        }
    • To return a Forms XAML Page: In the constructor App(), set the Forms XAML Page QuickStart as the MainPage. The following code shows the class constructor App(), after completing this step.
      C#
      Copy Code
      public App()
        {
           // The root page of your application
           MainPage = new QuickStart();
         }
  3. Some additional steps are required to run iOS and WinPhone apps:
    • iOS App:
      1. In the Solution Explorer, double click AppDelegate.cs inside YourAppName.iOS project to open it.
      2. Add the following code to the FinishedLaunching() method.
        C#
        Copy Code
        Xuni.Forms.Calendar.Platform.iOS.Forms.Init();
    • WinPhone App:
      1. In the Solution Explorer, expand the MainPage.xaml inside YouAppName.WinPhone project.
      2. Double click the MainPage.xaml.cs to open it and add the following code to the class constructor.
        C#
        Copy Code
        Xuni.Forms.Calendar.Platform.WinPhone.XuniCalendarRenderer.Init();

 

 


Copyright © GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback