This is a mirror of official site: http://jasper-net.blogspot.com/

Managing Silverlight resources contained in external assemblies

| Wednesday, October 20, 2010
A year ago, I’ve written a post about Managing WPF resources contained in external assemblies.

I am using this pattern in every Prism application I’m developing, the main reason for this is  that I like having each module responsible for his own resources, especially it contains DataTemplates which couple Views to ViewModels.

In each of my module entry classes (which inherit from IModule) I usually add a method which is used on the Initialize phase.

The problem is that the code that has being used by WPF is very different from the code you need to use in Silverlight.

So here you go:

private static void RegisterResources()
{
   ResourceDictionary dictionary = new ResourceDictionary();
   StreamResourceInfo resourceInfo = Application.GetResourceStream(new Uri("[ASSEMBLY NAME];component/[SUBFOLDER IF ANY]/{DICTIONARY NAME].xaml", UriKind.Relative));
   StreamReader resourceReader = new StreamReader(resourceInfo.Stream);
   string xaml = resourceReader.ReadToEnd();
   ResourceDictionary resourceTheme = XamlReader.Load(xaml) as ResourceDictionary;
   Application.Current.Resources.MergedDictionaries.Add(resourceTheme);
}

Note: the strange Uri syntax, every [] is a place holder for you to put in your specific information.

Read more: Ariel's Remote Data Center

Posted via email from .NET Info

0 comments: