2
votes

in my application, i have a resource dictionary defined as a separate file. Now i want to access this dictionary from a c#-file (no code-behind file!)

What would be the best(fastest, cleanest) way to do this?

  • Create a ResourceDictionary in code and merge it with the existing one?

  • Add the ResourceDictionary to the application's resources and access them with Application.Current.Resources?

  • Some other way??

Greets,

Jürgen

1

1 Answers

4
votes

You can load resource dictionaries using App.LoadComponent(), e.g.:

var d = (ResourceDictionary)App.LoadComponent(new Uri("Dictionary1.xaml",UriKind.Relative));

Not really sure if it would be the fastest, but it is probably one of the cleaner ways.