Tuesday, May 8, 2012

Displaying your product version in a Windows 8 Metro App

When creating a package for the store, the wizard gives you an option to automatically increment the package version number. This version number is used for a variety of important things. Wouldn't it be useful to display this number to the user when doing support, or logging errors?

To access the version you can easily use

Package.Current.Id.Version;

This returns a PackageVersion, with the regular 4 version properties.

Format it like so:

PackageVersion packageVersion = Package.Current.Id.Version;
string.Format("{0}.{1}.{2}.{3}", packageVersion.Major, packageVersion.Minor, packageVersion.Build,packageVersion.Revision);

Extra points for turning this into an extension method if you'll be doing it in more than one place!

In my current app, I've decided to add it to the application resources, and then bind to it from wherever I want to display it.

No comments:

Post a Comment