在项目中,我有一个外部类库SkinDaemon,里面有一个资源文件MacStyledWindow.xaml。我把生成的DLL导向了主项目的Debug目录下。
在主项目中的APP文件中,我添加如下代码,以便能够在项目中使用资源文件:
View Code
<Application x:Class="MarkitWireAPITestTool.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="LoginWindow.xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/SkinDaemon;component/Resource Dictionaries/MacStyledWindow.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application>
然后在前台,直接利用 Style="{StaticResource MacWindowStyle}"来引用,结果发现项目可以运行,显示结果正确,就是设计状态不能使用,一直提示我:
Error 7 Value 'pack://application:,,,/SkinDaemon;component/Resource Dictionaries/MacStyledWindow.xaml' cannot be assigned to property 'Source'. Could not load file or assembly 'SkinDaemon, Culture=neutral' or one of its dependencies. The system cannot find the file specified. F:\MarkitWireAPITestTool(WPF)\MarkitWireAPITestTool\MarkitWireAPITestTool\App.xaml 8 37 MarkitWireAPITestTool
原因是什么呢?
其实很简单,请在主项目中添加对SkinDaemon类库的DLL引用即可。