[assembly: Xamarin.Forms.ExportRenderer(
typeof
(Telerik.XamarinForms.Input.RadCalendar),
typeof
(Telerik.XamarinForms.InputRenderer.Android.CalendarRenderer))]
[assembly: Xamarin.Forms.ExportRenderer(
typeof
(Telerik.XamarinForms.Input.RadCalendar),
typeof
(Telerik.XamarinForms.InputRenderer.Android.CalendarRenderer))]
namespace
X_Calendar.Droid
{
[Activity(Label =
"X_Calendar"
, Icon =
"@drawable/icon"
, MainLauncher =
true
, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public
class
MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
protected
override
void
OnCreate(Bundle bundle)
{
base
.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(
this
, bundle);
LoadApplication(
new
X_Calendar.App());
}
}
}
[assembly: Xamarin.Forms.ExportRenderer(
typeof
(Telerik.XamarinForms.Input.RadCalendar),
typeof
(Telerik.XamarinForms.InputRenderer.iOS.CalendarRenderer))]
[assembly: Xamarin.Forms.ExportRenderer(
typeof
(Telerik.XamarinForms.Input.RadCalendar),
typeof
(Telerik.XamarinForms.InputRenderer.iOS.CalendarRenderer))]
namespace
X_Calendar.iOS
{
[Register(
"AppDelegate"
)]
public
partial
class
AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public
override
bool
FinishedLaunching(UIApplication app, NSDictionary options)
{
new
Telerik.XamarinForms.InputRenderer.iOS.CalendarRenderer();
global::Xamarin.Forms.Forms.Init();
LoadApplication(
new
X_Calendar.App());
return
base
.FinishedLaunching(app, options);
}
}
}
[assembly: Xamarin.Forms.ExportRenderer(
typeof
(Telerik.XamarinForms.Input.RadCalendar),
typeof
(Telerik.XamarinForms.InputRenderer.WinPhone.CalendarRenderer))]
[assembly: Xamarin.Forms.ExportRenderer(
typeof
(Telerik.XamarinForms.Input.RadCalendar),
typeof
(Telerik.XamarinForms.InputRenderer.WinPhone.CalendarRenderer))]
namespace
X_Calendar.WinPhone
{
public
partial
class
MainPage : global::Xamarin.Forms.Platform.WinPhone.FormsApplicationPage
{
public
MainPage()
{
InitializeComponent();
SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;
global::Xamarin.Forms.Forms.Init();
LoadApplication(
new
X_Calendar.App());
}
}
}
using
Telerik.XamarinForms.Input;
namespace
X_Calendar
{
public
class
Appointment : IAppointment
{
public
DateTime EndDate
{
get
;
set
;
}
public
DateTime StartDate
{
get
;
set
;
}
public
string
Title
{
get
;
set
;
}
}
}
namespace
X_Calendar
{
public
static
class
MyStaticFields
{
public
static
ObservableCollection<Appointment> Appointments;
}
}
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
ContentPage
xmlns
=
"http://xamarin.com/schemas/2014/forms"
xmlns:telerik
=
"clr-namespace:Telerik.XamarinForms.Input;assembly=Telerik.XamarinForms.Input"
x:Class
=
"X_Calendar.AppointmentsPage"
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
>
<
RowDefinition.Height
>
<
OnPlatform
x:TypeArguments
=
"GridLength"
>
<
OnPlatform.iOS
>30</
OnPlatform.iOS
>
<
OnPlatform.Android
>50</
OnPlatform.Android
>
<
OnPlatform.WinPhone
>70</
OnPlatform.WinPhone
>
</
OnPlatform
>
</
RowDefinition.Height
>
</
RowDefinition
>
<
RowDefinition
>
<
RowDefinition.Height
>
<
OnPlatform
x:TypeArguments
=
"GridLength"
>
<
OnPlatform.iOS
>30</
OnPlatform.iOS
>
<
OnPlatform.Android
>50</
OnPlatform.Android
>
<
OnPlatform.WinPhone
>70</
OnPlatform.WinPhone
>
</
OnPlatform
>
</
RowDefinition.Height
>
</
RowDefinition
>
<
RowDefinition
Height
=
"*"
/>
</
Grid.RowDefinitions
>
<
Button
Grid.Row
=
"0"
Text
=
"Add Appointment"
Clicked
=
"AddButtonClicked"
/>
<
Button
Grid.Row
=
"1"
Text
=
"Delete Appointment"
Clicked
=
"DeleteButtonClicked"
/>
<
telerik:RadCalendar
Grid.Row
=
"2"
x:Name
=
"calendar"
/>
</
Grid
>
</
ContentPage
>
public
App()
{
// The root page of your application
MainPage =
new
NavigationPage(
new
AppointmentsPage());
}
using
Telerik.XamarinForms.Input;
namespace
X_Calendar
{
public
partial
class
AppointmentsPage : ContentPage
{
static
AppointmentsPage()
{
MyStaticFields.Appointments =
new
ObservableCollection<Appointment>() {
new
Appointment() { StartDate = DateTime.Now.AddDays(-1), EndDate = DateTime.Now.AddDays(-1).AddMinutes(1), Title =
"Call Steve"
} };
MyStaticFields.Appointments.Add(
new
Appointment() { StartDate = DateTime.Now, EndDate = DateTime.Now.AddMinutes(1), Title =
"Tickets"
});
MyStaticFields.Appointments.Add(
new
Appointment() { StartDate = DateTime.Now.AddDays(3), EndDate = DateTime.Now.AddDays(3).AddMinutes(1), Title =
"Travel"
});
}
public
AppointmentsPage()
{
InitializeComponent();
this
.calendar.AppointmentsSource = MyStaticFields.Appointments;
}
protected
override
void
OnAppearing()
{
base
.OnAppearing();
}
void
AddButtonClicked(
object
sender, EventArgs e)
{
Navigation.PushAsync(
new
AddAppointmentPage(),
true
);
}
void
DeleteButtonClicked(
object
sender, EventArgs e)
{
Navigation.PushAsync(
new
DeleteAppointmentPage(),
true
);
}
}
}
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<ContentPage xmlns=
"http://xamarin.com/schemas/2014/forms"
x:Class=
"X_Calendar.AddAppointmentPage"
>
<StackLayout>
<Label Text=
"Add Appointment Page"
FontSize=
"30"
VerticalOptions=
"Center"
HorizontalOptions=
"Center"
/>
<StackLayout Orientation=
"Horizontal"
>
<Label Text=
"Start: "
/>
<DatePicker x:Name=
"startDatePicker"
HorizontalOptions=
"StartAndExpand"
/>
</StackLayout>
<StackLayout Orientation=
"Horizontal"
>
<Label Text=
"End: "
/>
<DatePicker x:Name=
"endDatePicker"
HorizontalOptions=
"StartAndExpand"
/>
</StackLayout>
<StackLayout Orientation=
"Horizontal"
>
<Label Text=
"Title: "
/>
<Entry x:Name=
"title"
WidthRequest=
"150"
/>
</StackLayout>
<Button Text=
"Done"
Clicked=
"DoneButtonClicked"
VerticalOptions=
"Center"
HorizontalOptions=
"Center"
/>
</StackLayout>
</ContentPage>
public
partial
class
AddAppointmentPage : ContentPage
{
public
AddAppointmentPage()
{
InitializeComponent();
}
void
DoneButtonClicked(
object
sender, EventArgs e)
{
MyStaticFields.Appointments.Add(
new
Appointment()
{
StartDate = startDatePicker.Date,
EndDate = endDatePicker.Date.AddSeconds(1),
Title = title.Text ==
null
?
"(No Title)"
: title.Text
});
Navigation.PopAsync(
true
);
}
}
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
ContentPage
xmlns
=
"http://xamarin.com/schemas/2014/forms"
x:Class
=
"X_Calendar.DeleteAppointmentPage"
>
<
StackLayout
>
<
Label
Text
=
"Delete Appointment"
FontSize
=
"30"
VerticalOptions
=
"Center"
HorizontalOptions
=
"Center"
/>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"50"
/>
<
RowDefinition
Height
=
"*"
/>
<
RowDefinition
Height
=
"50"
/>
</
Grid.RowDefinitions
>
<
Label
Text
=
"Select appointment to delete"
/>
<
ListView
x:Name
=
"list"
Grid.Row
=
"1"
>
<
ListView.ItemTemplate
>
<
DataTemplate
>
<
TextCell
Text
=
"{Binding Title}"
/>
</
DataTemplate
>
</
ListView.ItemTemplate
>
</
ListView
>
<
Button
Text
=
"Done"
Clicked
=
"DeleteButtonClicked"
Grid.Row
=
"2"
/>
</
Grid
>
</
StackLayout
>
</
ContentPage
>
public
partial
class
DeleteAppointmentPage : ContentPage
{
public
DeleteAppointmentPage()
{
InitializeComponent();
this
.list.ItemsSource = MyStaticFields.Appointments;
}
void
DeleteButtonClicked(
object
sender, EventArgs e)
{
MyStaticFields.Appointments.Remove((Appointment)
this
.list.SelectedItem);
Navigation.PopAsync();
}
}
You can find the complete project at GitHub. Of course, to run it, you need to download Telerik UI for Xamarin.
Happy coding!
Update: Check out the newly released Telerik Tagit, a cross-platform native mobile Xamarin app. We give you source code and a six-part walkthrough of how it was created. Check out how we implemented the Calendar control in that app, right here!