How to set a relative path/Uri in ResourceDictionary's source
Asked Answered
S

1

28

I am trying to refer to a MergedDictionaries.SharedStyles project which has all Styles that has to be used allover application. So here i have different styles under different folders as Resource Dictionaries. so finally i have Merged them into AllSharedStyles.xaml and have that at Styles project level.

Now I have another ResourceDictionary at Solution level <> which refers to AllSharedStyles.xaml resource dictionary <<>>. This ResourceDictionary is added as a link to all my modules in solution.

Issue here is In my SharedResourceDictionary i am having following MergedDictionaries

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/MergedDictionaries.SharedStyles;component/AllSharedStyles.xaml" />
    <ResourceDictionary Source="/View/LocalResource.xaml" /> 
</ResourceDictionary.MergedDictionaries>

Project architecture

I have refered to common Resource first then my local inorder to override(only if required) any styles specific to module.

Now when i run the application it complains

'Set property 'System.Windows.ResourceDictionary.Source' threw an exception.' Line number '5' and line position '10'.

Thats the error message.

With my understanding it is looking for proper reference. I also tried using Pack URL ref: Pack URLss. Here is the pack url:

 <ResourceDictionary Source="pack://application:,,,/MergedResourceDictionaries.Styles;component/component/AllSharedStyles.xaml" />

So any suggestions on How to have a relative path here????

Sorry for my description/projection of problem

Slip answered 22/8, 2012 at 3:58 Comment(0)
S
37

Finally worked out solution:

<ResourceDictionary Source="../SharedResourceDictionary.xaml" /> 

Changed it to relative path and given root path.

Slip answered 31/10, 2012 at 5:45 Comment(2)
Note that this won't work if you include the assembly in another project. You would require an absolute path which, in your case, would be /Shell.Run;component/SharedResourceDictionary.xamlTobit
Using a relative path, ../../../Common/Editing/Controls/ItemTemplates.xaml, worked for me as well, although VS had suggested an absolute path, /Common/Editing/Controls/ItemTemplates.xaml, and the editor was able to resolve it (e.g. when using F12 to do to jump to the file)...Mcadams

© 2022 - 2024 — McMap. All rights reserved.