Question

I have defined a set of Custom Controls, Styles, Resource Dictionaries, etc.. that will be used as a basis for all applications my team develops. I have tried the route of copying everything between projects and this just causes namespace related find/replace issues. I have read that the best way to handle this is to create a library that is referenced from each project however, from what I've read embedding and using resource dictionaries from within referenced library's can be a bit quirky. What is the recommended method of handling this? Are there any good tutorials out there? I have scoured the vast internet's for a solution but haven't found anything satisfying... maybe I and using the wrong search terms?? Any help would be appreciated.

Was it helpful?

Solution

You can definitely use an external library and pull in ResourceDictionaries, images, etc from it. There are a lot of different options for path syntax in XAML but probably the most stable for this type of situation is the form /<assemblyName>;component/<folder>/<fileName>

If you have a project named MyCompany.SharedResources and you want to use a TextStyles.xaml dictionary in the Styles folder merging that into another project would look like:

<ResourceDictionary>
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/MyCompany.SharedResources;component/Styles/TextStyles.xaml" />
  </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top