我已经阅读了很多关于 ResourceDictionaries
的内容,但我不确定它们与文件系统的关系。
如果我引用一个 ResourceDictionary Source="/X/a.b"
,这是否意味着我可以将资源文件 a.b 放在目录 X 下,其中 X 与我的 bin, obj, App.xaml
等?
我正在尝试使用 Selen.Wpf.SystemStyles 做这样的事情,但我收到了 FileNotFound
错误。
The assembly with display name 'Selen.Wpf.SystemStyles' failed to load in the 'Load' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'Selen.Wpf.SystemStyles, Culture=neutral' or one of its dependencies. The system cannot find the file specified.
我已将所有资源放入目录中,并已确认这些文件符合我认为的文件系统预期。 我是否遗漏了其他约定?
导入资源的代码为:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="pack://application:,,,/Selen.Wpf.SystemStyles;component/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
最佳答案
您的代码尝试从名为 Selen.Wpf.SystemStyles
的外部程序集加载资源文件。里面有一个名为 Styles.xaml
的嵌入式资源文件。
从异常来看,您似乎缺少对提到的程序集的引用,或者它没有被复制到 bin\Debug
目录。
同时读入 MSDN 上的包 URI .
关于c# - C# WPF项目正确添加样式资源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31249554/