2011-10-09 52 views
2

下面的圖片是我想要的。我只是想在2個以上的項目中共享xaml資源

enter image description here

* dgCommon類有沒有問題。

我想在CommonStyles目錄中共享一個xaml資源。在項目1中,我添加了xamls作爲'在鏈接'添加文件打開對話框窗口中的選項。

以下是項目1.

enter image description here

溶液視圖它在設計時加載好。因爲使用這些資源的窗口在設計時顯示正確狀態。

但由於編譯錯誤,我無法運行項目1。編譯器說'不能找到\ commonstyles \ button.xaml''。

以下代碼是我加載這些資源xaml文件的方式。 (在App.xaml中)

<ResourceDictionary.MergedDictionaries> 

    <ResourceDictionary Source="CommonStyles\Button.xaml" /> 

... 

</ResourceDictionary> 

這個標籤在過去的時間裏工作正常。 (我在指定的文件夾中找到xaml文件的時間,而不是'添加到鏈接')

我不敢相信這個問題沒有簡單的解決方案。 我希望這只是由於我缺乏可讀性而造成的。

我該如何實現它?

回答

1

Add as link對xaml文件不起作用。嘗試使用Pack URI引用文件中的常見DLL:

<ResourceDictionary.MergedDictionaries> 
    <ResourceDictionary Source="/CommonStyles;component/CommonStyles/Button.xaml" /> 
</ResourceDictionary.MergedDictionaries> 

More information on this issue here

+0

「添加爲鏈接」有很多問題。所以我決定做一個新的wpf庫DLL。謝謝。 – mjk6026