XamlEssentials 3.2 - Tons of New Stuff
Next month, I'll be speaking at the annual Tallahassee Code Camp, presenting a solution we've been working on to streamline in-app customer support across a variety of platforms. Along the way, I've been working on major improvements to the software I released at my last speaking engagement, XamlEssentials. I just released Version 3.2, so I thought I'd take a minute to go over the changes since the last time I talked about it.
This is one of my favorite parts of a Windows Phone speech demo on MSDN. It allows you to easily save application settings with a default value, like this:
public static StoredItem<bool> IsProgramStarted = new StoredItem<bool>("isProgramStarted", false);
In version 2.1, this method worked with Windows Phone to store to IsolatedStorageSettings. But in Version 3.2, I expanded it to also work with ApplicationData.LocalSettings for Windows 8.x apps. With versions for Windows Phone 7.5, 8, Windows 8, and 8.1, it should help make your cross-platform code a little more portable.
This neat little tool pulls the Store details from Windows Store and Windows Phone Store manifests. This is not the first tool that does it, but I am certain mine is the best. Most incarnations you read on StackOverflow show the XML file being read every time you access a detail like the Publisher or Version. My version reads the file once, in the static constructor. Because, logically speaking, none of the information in that file is ever going to change while the app is executing.
I use this tool to build all of my "About" pages. Instead of re-building that page every time, I now have a control in my library that does the work for me, every time. (Maybe that control will make it into a future release of XamlEssentials.) Anyway, just call the static property ApplicationInfoHelper.Version, or any of the other available static properties, and you can rest easy knowing you're using the most efficient method possible.
This helper first appeared in Version 2.3 a few months ago. Now, in Version 3.2, I've added support for Windows Store apps. Windows 8.1 gives you the cleanest API to work with, but we still had to do some XML reading for Windows 8.0 apps. Either way, now a single API call does all the work for all Windows platforms.
Map Query Extensions
For whatever reason, Microsoft decided that the calls to Mapping APIs on Windows Phone 8 would not be awaitable. Hopefully that little issue will be addressed in Windows Phone 8.1. Until there, there is a nifty little ExecuteAsync extension method on the Query base object that comprises all Map query calls. This method lets you properly await these requests, and was generously donated by Nigel Sampson from this blog post. As you might have gathered, this is specific only to the Windows Phone 8 version of the library. This was added way back in Version 2.2, and has proven to be quite useful.
This one's brand new for Version 3.2. I've seen several different solutions out there for gathering application usage statistics, but none of them are perfect in my opinion. The one I like the most is Telerik's ApplicationUsageHelper, but that particular tool uses an XML file in IsolatedStorage to save it's information, and it doesn't grab all the information I need. I'm also not a big fan of how you have to pass in the version every time you initialize the app... it's not very well thought out.
So now XamlEssentials includes its own helper. Based on the improvements from ApplicationInfoHelper and StoredItem, we have a solution that works for both Windows Phone and Windows Store apps. You simply call StatsHelper.Initialize(); as early as possible in app startup, and StatsHelper.TearDown(); as late as possible in the shutdown handler. We'll track how many times the app has run, when the current version was installed, how many unhandled exceptions have occurred for the current and every version, and more. None of this information is transmitted anywhere with this Helper, they are stored locally with the StoredItem object.
These stats persist between updates, but will not stick around after an uninstall and reinstall, so just be aware of that. Anyway, with the inclusion of unhandled exception stats (like the "last known good" shutdown date), you now have a bit more useful information if you're trying to track down a problem.
Like a lot of my other work, the code for this is open source. So if you have any useful converters or tools for Windows 8, Windows Phone, Silverlight, or WPF, please fire up a pull request and send it my way.