wpf 如何在 ResourceDictionary 的源中设置相对路径/Uri

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12066125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 23:29:37  来源:igfitidea点击:

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

wpfxamlresourcedictionaryprism-4

提问by WPFKK

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.

我试图引用一个 MergedDictionaries.SharedStyles 项目,该项目具有必须在整个应用程序中使用的所有样式。所以在这里我在不同的文件夹下有不同的样式作为资源字典。所以最后我将它们合并到 AllSharedStyles.xaml 并在 Styles 项目级别使用它。

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.

现在我在解决方案级别有另一个 ResourceDictionary <>,它指的是 AllSharedStyles.xaml 资源字典 <<>>。此 ResourceDictionary 作为链接添加到我的解决方案中的所有模块。

Issue here is In my SharedResourceDictionary i am having following MergedDictionaries

这里的问题是在我的 SharedResourceDictionary 中,我正在关注 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:

根据我的理解,它正在寻找适当的参考。我也尝试使用 Pack URL ref: Pack URLss。这是包的网址:

 <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

抱歉我对问题的描述/预测

回答by WPFKK

Finally worked out solution:

终于找到了解决办法:

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

Changed it to relative path and given root path.

将其更改为相对路径并给定根路径。