Tuesday, October 20, 2009

Passing dates in XAML

Recently I had the need for an encapsulated, reusable 'About Box' control that I could use throughout a number of Silverlight applications. I then wrote a user control that would serve this purpose. The AboutBox displays application releases that are grouped by the application version, and a list of changes/updates included in that version. An example of this can be seen below:


Although the use and implementation of the AboutBox user control is beyond the scope of this article, one of the features of the AboutBox was to enable the developer to specify a date for a product release item. I made provision for this by creating a DateTime property called Date in the VersionInformation class. However, I encountered a problem when trying to specify a value for this property in the XAML of the page consuming the AboutBox user control

I realized that XAML natively does not know how to convert a string to a DateTime value, and setting the Date property as Date="12 January 2009" would result in an AG_E_UNKNOWN_ERROR XAML parser error when running the application.

Thankfully, there is a way to resolve this. The answer lies in TypeConverter, and the full article can be found at CodeProject

No comments:

Post a Comment

Could you do me a SOLID mate?

Wow, it’s been a while! Nearly nine years since my last blog post . A lot has changed since then – some for the better, some for the worse....