2011-07-08 45 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"/>