2011-07-08 30 views
0

我已经创建一个WPF扩展到现有的Win32 MFC客户端应用程序。在位于我的WPF类库一个用户控件,我合并库如下:WPF资源访问从不同的程序集,如果没有App.xaml

<ResourceDictionary.MergedDictionaries>     
       <ResourceDictionary Source="MyResourceDLL;Component/dictionaries/styles.xaml"/> 
      </ResourceDictionary.MergedDictionaries> 

我也试过

<ResourceDictionary.MergedDictionaries>     
        <ResourceDictionary Source="pack://application:,,,/MyResourceDLL;Component/dictionaries/styles.xaml"/> 
       </ResourceDictionary.MergedDictionaries> 

在任何情况下,我得到以下XamlParseException:

System.Windows.Markup.XamlParseException occurred
Message =“MyResourceDLL; Component/dictionaries/styles.xaml' valu e不能被分配给属性 对象'Source' 'System.Windows.ResourceDictionary'。 找不到资源 'ems.wpf.resources; component/dictionaries/styles.xaml'。 错误在 标记文件对象 “System.Windows.ResourceDictionary” “SARMaster.Maryln.EphemerisLib;组件/ getephemeriscontrol.xaml” 线9的位置37”

我没有一种方法可以加载一个没有被主项目引用的相对DLL?

+0

不明白。为什么不引用包含资源字典的程序集?我想,你需要进一步解释你的情况。 –

+0

您是否试过[this](http://stackoverflow.com/questions/709087/load-a-resourcedictionary-from-an-assembly)? – dowhilefor

+0

Kent,WPF类库引用包含资源字典的程序集。我需要告诉宿主MFC应用程序将所有托管DLL复制到其输出目录或其他东西。不像WPF主机,将此程序集引用添加到MFC项目不会将其复制到其输出目录。如果我自己手动复制文件,一切都很好。 –

回答

0

最近我一直在看同样的问题。编译一个Win32 CLR项目时,MFC项目引用的程序集的依赖关系不会被复制,所以我简单地设置生成后事件以将相应的程序集复制到$(TargetDir)。

不理想,但我相信这是设计。

0

我得到了同样的问题,我找到了解决方案。我需要删除我的ContentPresenter的样式。这条线创建XamlParseException:

<ContentPresenter.Resources> 
    <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource TextStyle}"/> 
</ContentPresenter.Resources> 

和修复这个错误后,我需要做的这些步骤有东西100%的工作:

这里我的项目:

  • StyleProject :我想要使用的Class Library项目。它包含了我的风格
  • MainProject:将使用的样式

为此项目:

  1. 加入我的MainProject里面我StyleProject的参考(see here
  2. 创建一个ResourceDictionary,称为MyStyle。XAML里面我MainProject
  3. 添加我的StyleProject的不同的字典以下this answerMyStyle.xaml
  4. 添加MyStyle.xaml的App.xaml使用下面的代码

代码:

<ResourceDictionary Source="Resources/MyStyle.xaml"/>