[UPDATED: This article was meant to share a quick hack that I created. I am not endorsing this as a best practice that you should incorporate into your applications. I’m offering it as an option to those of you building apps that only use the English language.]
Yesterday, I was working on a Windows Phone application that is very date-centric. I show the user a list of events for a specific day, and the page always loads data for “today” by default. They can always change it (I’m using a DatePicker for that), but I wanted to give them an easy way to return to whatever “today” may be.
I’d seen this before, in the Calendar app that comes on Windows Phone by default. It looks like this:
As you can see, there is a “today” button in the ApplicationBar. (In the image, today must be July 7th.) Anyways, I did some investigation, and came to a conclusion that either that image is being generated on the fly, or they’ve included 366 images in their project, to accommodate every possible month/date combination.
Since I’ve never done any dynamic image generation before, it seemed like more work that I was prepared to accomplish in the short timeline I had to finish this application. So, I went ahead and created the 366 images that are necessary to make this functionality happen.
To change the IconUri property of an ApplicationBarIconButton, you just need this one line of code:
((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IconUri = new Uri("/icons/dates/" + DateTime.Now.Month + "-" + DateTime.Now.Day + ".png", UriKind.Relative);
Finally, you’re probably interested in downloading this set of images, so you don’t have to spend the countless hours (it was less than 2) I spent creating them. So, here they are:
Or, if that’s not convenient, you can download the entire collection of Windows Phone Date Icons in a ZIP file here.
These images are completely free to use, I only ask that you comment here on how you used them. Fair?
Leave a Reply