Tuesday, September 9, 2008

XamlReader in .Net 3.5 SP1

If you've done any WPF development involving dynamic object creation from XAML, you're probably familiar with XamlReader.Load().

There are several overloads which take a stream or an XmlReader. This usually leads to an excessively verbose syntax in my code, where I generally have the XAML string in memory:

MyClass myObject = (MyClass) XamlReader.Load(XmlReader.Create(new StringReader(myObjectXamlString)));


With SP1, we now have the object of using XamlReader.Parse() which simply takes in a string. All of my verbose code that follows the style above now becomes:

MyClass myObject = (MyClass) XamlReader.Parse(myObjectXamlString);

Life keeps getting better and better!

0 comments: