Introducing XamlEssentials - Cross-Platform Helpers for Microsoft XAML
A little over a year ago I gave a quick talk at the Tampa Windows Phone Developers Group about how to write cross-platform XAML helpers. It demonstrated an alternative approach to using Portable Class Libraries, which are useful but limit your code's capabilities to the lowest common demonimator. For this demo, I created a project called XamlEssentials, which took many of the ValueConverters I'd written for other projects, and combined them in such a way that a single file could be used to define capabilities for multiple platforms, with each leveraging the platform to its fullest. I posted the assemblies to NuGet, and then promptly forgot about it completely.
Unbeknownst to me, it had amassed over 500 downloads, which, while not amazing, caught me by surprise when I was cleaning out our NuGet account a couple weeks ago. So last weekend, I cleaned up the code and added a Windows Phone 8-specific project. I pushed v2 up to NuGet, and just a few minutes ago I also published the source code to GitHub.
In a future post, I'll talk about the techniques I used to create the package. But for now, here's a list of what the package contains, and the platforms each one is available on:
- BooleanToVisibilityConverter (ALL)
- CollectionCountToVisibilityConverter (ALL)
- ContactImageConverter - Converts a Microsoft.Phone.UserData.Contact to that user's Avatar. (WP8)
- IntegerIsNotZeroConverter (ALL)
- IntEqualToVisibilityConverter (ALL)
- IntGreaterOrEqualToVisibilityConverter (ALL)
- IntLessThanToVisibilityConverter (ALL)
- IntNotEqualToVisibilityConverter (ALL)
- IntToEnumConverter (ALL)
- ItemToIndexConverter (ALL)
- LocalizableEnumToFriendlyNameConverter (ALL)
- MultiVisibilityConverter - a MultiValueConverter that allows you to chain Converters together to evaluate a complex situation.
- NullToVisibilityConverter (ALL)
- StringFormatConverter - A Single- and MultiBindingConverter that outputs a string from a given set of bindings.
- StringNotEmptyToVisibilityConverter (ALL)
- StringToBooleanConverter (ALL)
- StringToEnumConverter (ALL)
- TypeComparisonToVisibilityConverter (ALL)
- ConvertibleMarkupExtension (.NET 4, .NET 4.5, SL5)
- EnumListExtension (.NET 4, .NET 4.5, SL5)
More tools will be added to this list over time.
If you have any code nuggets that you think would be useful to the project, please feel free to make a pull request. We'll list your contribution on the GitHub page and make sure it will run on all possible platforms. And if you have any issues, please file a bug.