Long term purpose of this project is to create commonly used controls for Windows Phone 7 Silverlight applications that are not available in standard set of controls.

Now available on NuGet - Install-Package WPControls or https://nuget.org/packages/WPControls

First control I am working on is Windows Phone 7 Calendar control. It supports the following features:
  • Next/Previous month buttons
  • Ability to provide converters to color day number or date cell background
  • Ability to select a date and apply background color
  • Data binding to SelectedDate
  • Support for context menu from Silverlight toolkit (new in 1.1)
  • Explicit refresh and source of dates

Calendar also supports the following events
  • MonthChanging is fired before calendar is rebuilt for the next month. Can be used to setup data for converters
  • MonthChanged is fired after calendar is rebuilt for new month/year
  • SelectionChanged is fired when a user selects a date

In release 1.2 I added the following features:
  • Add SelectedYear and SelectedMonth properties. Both are bindable to the view model.
  • Add ability to remove highlights from selected date via ShowSelectedDate property.
  • Add ability to hide month navigation buttons via ShowNavigationButtons property.

In release 1.3 I added the following feature:
  • Calendar supports flicks right to left / left to right to increment or decrement months.
  • Calendar also supports flicks top to bottom /bottom to top to increment or decrement years.
To enable support you will need to set property on the calendar control – EnableGestures – to true.

In release 1.3 5 added the following feature:
  • Calendar supports display of week number.
  • You can set it to None(default), Week of the month or week of the year..
To enable support you will need to set property on the calendar control – WeekNumberDisplay– to appropriate value.

In release 1.3.6 added globalization support and published to NuGet
Now available on NuGet - Install-Package WPControls or https://nuget.org/packages/WPControls

In release 1.4.0 added support for minimum and maximum dates for previous/next month/year navigation.

In release 1.5 added support for changing start day of the week.

Check my blogs posts about calendar control:
http://dotnetspeak.com/index.php/2011/01/windows-phone-7-project/
http://dotnetspeak.com/index.php/2011/01/windows-phone-7-controls-project-update/

As part of download, you are provided with a working sample that shows how to do converters and calendar control without converters.

Here is the markup you can use in both cases:
Sample calendar control:
xmlns:wpControls="clr-namespace:WPControls;assembly=WPControls"
<wpControls:Calendar x:Name="Cal"/>

Using converters:
xmlns:wpControls="clr-namespace:WPControls;assembly=WPControls"

<phone:PhoneApplicationPage.Resources>
<local:BackgroundConverter x:Key="BackgroundConverter"/>
<local:DayNumberConverter x:Key="DayNumberConverter"/>
</phone:PhoneApplicationPage.Resources>

<wpControls:Calendar
x:Name="Cal"
BackgroundConverter="{StaticResource BackgroundConverter}"
ForegroundConverter="{StaticResource DayNumberConverter}"
/>

Converts simply have to implment a simple interface with one method:
public class BackgroundConverter : IDateToBrushConverter
{

public Brush Convert(DateTime dateTime, bool isSelected, Brush defaultValue)
{
if (dateTime == new DateTime(DateTime.Today.Year, DateTime.Today.Month, 5))
{
return new SolidColorBrush(Colors.Yellow);
}
else
{
return defaultValue;
}
}
}

public class DayNumberConverter : IDateToBrushConverter
{

public Brush Convert(DateTime dateTime, bool isSelected, Brush defaultValue)
{
if (dateTime == new DateTime(DateTime.Today.Year, DateTime.Today.Month, 7))
{
return new SolidColorBrush(Colors.Orange);
}
else if (dateTime == new DateTime(DateTime.Today.Year, DateTime.Today.Month, 5))
{
return new SolidColorBrush(Colors.Purple);
}
else
{
return defaultValue;
}
}
}


Of course, instead of hard-coded date you can drive them based off your data on the phone. On a second note, if you need a simple, easy to use, yet powerful database for your Windows Phone 7 application, check out my other project on CodePlex: http://winphone7db.codeplex.com/
Here is what the control looks like on the phone:

CalendarControl.png

Last edited Sep 22, 2013 at 2:36 PM by SergeyBarskiy, version 21