Skip to content
Rebecca edited this page May 6, 2017 · 7 revisions

Getting started

iOS

On iOS please call XamForms.Controls.iOS.Calendar.Init(); in your AppDelegate.cs of your iOS project:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
        global::Xamarin.Forms.Forms.Init();
        XamForms.Controls.iOS.Calendar.Init();   // <<<<<!!! Please insert this
        LoadApplication(new App());

        return base.FinishedLaunching(app, options);
}

Android

On Android please call XamForms.Controls.Droid.Calendar.Init(); in your MainActivity.cs of your Android project:

protected override void OnCreate(Bundle bundle)
{
	base.OnCreate(bundle);

	global::Xamarin.Forms.Forms.Init(this, bundle);
	XamForms.Controls.Droid.Calendar.Init();  // <<<<<!!! Please insert this
	LoadApplication(new App());
}

Windows

On Windows please call XamForms.Controls.Windows.Calendar.Init(); in your App.xaml.cs of your Windows project:

protected override void OnLaunched(LaunchActivatedEventArgs e)
{

#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                Xamarin.Forms.Forms.Init(e);
                XamForms.Controls.Windows.Calendar.Init(); // <<<<<!!! Please insert this

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
}

Add Calendar

Here is a sample:

new Calendar
{
  BorderColor = Color.Gay,
  BorderWidth = 3,
  BackgroundColor = Color.Gay,
  StartDay = DayOfWeek.Sunday,
  StartDate = DateTime.Now
}

XAML:

First add the xmlns namespace:

xmlns:controls="clr-namespace:XamForms.Controls;assembly=XamForms.Controls.Calendar"

Then add the xaml:

<controls:Calendar Padding="10,0,10,0" StartDay="Monday" SelectedBorderWidth="4" DisabledBorderColor="Black">

Troubleshoot

If the number of dates is not correct and do not change when the month is change This is caused by the CalendarButtons not being attached to the CalendarButtonRenderer (platform specific). See issues: #2,#6, #10

  • Please check that you really added the nuget package to the iOS, Android or Windows project.
  • Please check that the XamForms.Controls.Calendar.<Platform>.dll is added to your project.
  • Please check if you have called the init methods described above.
  • If nothing else helps, adding this to your platform projects AssemblyInfo.cs file:
[assembly:Xamarin.Forms.Platform.<Platform>.ExportRenderer(typeof(XamForms.Controls.CalendarButton),typeof(XamForms.Controls.<Platform>.CalendarButtonRenderer))]
Clone this wiki locally