RSS 2.0 Feed
RSS 2.0


Atom 1.0 Feed
Atom 1.0

  Dynamic XAML UI 


I just read a post from Mitch Walker (program manager on the Longhorn SDK team) about how they used XAML to make the Terrarium game application “skinnable”. I've never really been that into Terrarium - I made my own herbivore organism and all but I guess I just never really understood the game. Anyway, that's not my point. My point is that in this article it shows you how to do something really cool - and that is how you can dynamically apply style from a XAML file to your application at runtime.

Mitch shows in his article how he reads a directory for files ending in “_style.xaml” and cycles those as themes or skins and then applies them to the application without restarting. Now that is just cool. And it is brain-dead easy. Take a look at the relevant code to load the XAML into the application's resources at runtime:

Stream stream = File.OpenRead(styleFileName);

FrameworkElement resourceElement = (FrameworkElement)Parser.LoadXml(stream);
resourceElement.Resources.Seal();
this.Application.Resources = resourceElement.Resources;

stream.Close();

“Huwah??“ you say?! No kidding. Now that is just plain cool. Take a look at Mitch's entire article here.




                   

Comments have been closed on this topic.



 

News


Also see my CRM Developer blog

Connect:              


Sponsor

Sections