Sunday, December 26, 2010

Calendar Control for Windows Phone 7 (WP7)

For my first WP7 application, Diabetes Manager, I needed a calendar control that would give users an easy way to enter their daily data. Unfortunately WP7 does not provide any calendar control; it does provide a Date and Time picker. But the picker control did not work for me as far as user experience is concerned. And since I did not find anything on the internet, I decided to write my own.

My calendar control gives users a view of the entire month and  they can click on any day to enter data for that day. The control is made up of two sections :

a) Month and Year selector at the top and
b) Grid of days at the bottom.

Users can navigate between months by clicking on left/right buttons and selecting a day would launch a data entry form.
The calendar control also provides visual cues via color scheme. For instance dates with no data are indicated with default white color; whereas dates with data are indicated with yellow color. Current date is indicated by Orange color.
The rounded rectangles are achieved by using a combination of Rectangle Shape with rounded borders and transparent button (which makes it click able).

IMPORTANT:  To display the different color schemes (white, yellow, orange) for different states, I initially set the Foreground property of the Button. But it would always revert back to the original color (White in this case). The workaround is to define button styles for various states in XAML as shown here and use it in the code as follows:

btn.Style = this.Resources["HasDataButtonStyle"] as Style;

I posted the entire source code for this control on Codeplex:


Anonymous said...

Would you consider sharing the code in a non LGPL/GPL license? Codeplex code cannot be used in any WP7 application. (

Anonymous said...

(Sorry about the earlier comment, it went out before I finished typing and didn't show up for a day due to moderation I believe)
Would you consider sharing the code in a non LGPL/GPL license? The windows phone 7 marketplace does not seem to publish any code that uses this license.( Request you to consider releasing your source code in another open source license like MIT or BSD which will allow wp7 app developers to use your calendar control. Thanks!

Mike B. said...

The license on the Codeplex project now appears to be MIT, so the issue is moot.

However, I don't believe the original poster is correct -- apps licensed under LGPL aren't allowed, because Microsoft has no channel to convey the source to recipients of the binaries (a requirement of distributing GPL apps). The primary difference between LGPL and GPL is that LGPL libraries can be used in apps with other licenses.