I’ve been doing this with a friend (Ines Azouz, a young Windows Phone developer Girl) few days ago and so I loved to share it with you, let’s take it easy, start your Visual Studio, create a new Windows Phone app and paste these code snippets (don’t worry, I’ll explain how it works after you test it)

The first two code snippets are too long, I used to share them on the web

Paste this code in XAML editor
And this in the C# code file

Have you tested it ? is it working ? move up anyways to the explaining and I’ve added a sample project for the tutorial (link at the end of the tutorial)

Let’s explain how it works and let’s start by what’s easy, the calendar is linked to a global DateTime object which is used to track the actual Month / Year, I used to make it global so this way it will make it easier to me to switch to the next or previous month, it looks very simple just like this

And to initialize the the calendar when the app starts up we’ve to call the Initialize_Calendar and assign Today’s date to the calendarDate object, very simply like this in the public MainPage() method

Let’s move a bit ahead to the previous and next month buttons and how they work, very simple they just add or subtract one month from the calendarDate object just like in this code

I left the hardest question to the end and here we came to it, no worry it’s not too difficult, just you need a little focus to get …

As you see the XAML contains a lot of StackPanel and basically there is 6 rows containing 7 Grid in each row and there is a TextBlock in every Grid that’s how it’s designed and the main StackPanel container is the only one that I gave a name which is Calendar.

So I used to access all the TextBlock objects through accessing the main StackPanel‘s Children (6 StackPanel items) and accessing every item’s Children (7 Grid items) every Grid has only one Children which is the TextBlock and change its value using a counter integer and some math expressions

But before doing this I used to get some useful data which are the the first day’s number in the week and the count of month’s days using these 3 lines

This way I’ll be able very easily to put the day number in the 2nd foreach loop just before the counter’s increasing instruction i++ like I’m showing down

That’s all, that’s how it works very easily !

Okay, how for an awesome and modern progress bar ? that’s the bonus of this tutorial

Here’s the XAML

Here’s the C# (can be used with a button to set a random value from 0 to 100)

There’s a sample available for this tutorial, click here to download it