Silverlight Calendar Control
The Silverlight Calendar control is great for scenarios where date selection by an end user is needed. Here we have a simple example which shows how to display the calendar in XAML and how to respond to date changes in C#.
You need to login to Download the Calendar example, If you do not have a login you can register for free!
How to Use the Calendar Control
To use it on your Silverlight page:
<UserControl x:Class="Calendar.Page"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:liquid="clr-namespace:Liquid;assembly=Liquid"
xmlns:extended="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
Width="400" Height="300">
<Canvas>
<extended:Calendar x:Name="testCal" Canvas.Top="10" Canvas.Left="10" />
</Canvas>
</UserControl>
In your Silverlight C# code behind file you can refer to your calendar using testCal. The Calendar has a SelectedDate property which allows you to set or read the currently selected date.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace Calendar
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
testCal.SelectedDatesChanged += new EventHandler<SelectionChangedEventArgs>(testCal_SelectedDatesChanged);
}
void testCal_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
{
DateTime selectedDate = testCal.SelectedDate.Value;
}
}
}
The Calendar exposes a click event which is fired (named SelectedDateChanged) when a day is clicked on, you can attach an event handler to this to read the date value.
Example Silverlight Calendar Control:
Rate this page:
1 Star
2 Star
3 Star
4 Star
5 Star
39 Ratings / 2.9 Average