2012-08-26 25 views
1

我已經創建了一個WPF應用程序(名爲「Ferhad.Wpf」)。然後我添加了兩個名爲「Ferhad.Wpf.Core」和「Ferhad.Wpf.SystemStyles」的類庫到解決方案。無法在app.xaml中找到MergedDictionaries

「Ferhad.Wpf.Core」中只有「Resources.xaml」。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 

    <SolidColorBrush x:Key="Foreground" Color="#FFFFFF" /> 
    <SolidColorBrush x:Key="BackgroundNormal" Color="#3F3F46" /> 
    <SolidColorBrush x:Key="BorderBrushNormal" Color="#54545C" /> 
    <SolidColorBrush x:Key="BorderBrushHighlighted" Color="#6A6A75" /> 
</ResourceDictionary> 

但也有 「ButtonStyles.xaml」 和 「Styles.xaml」 在 「Ferhad.Wpf.SystemStyles」。 這裏是 「ButtonStyles.xaml」:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <ResourceDictionary.MergedDictionaries> 
     <ResourceDictionary Source="pack://application:,,,/Ferhad.Wpf.Core;component/Resources.xaml" /> 
    </ResourceDictionary.MergedDictionaries> 
    <Style x:Key="StandartButton" TargetType="Button"> 
     <Setter Property="Visibility" Value="Visible" /> 
     <Setter Property="Foreground" Value="{StaticResource Foreground}" /> 
     <Setter Property="Background" Value="{StaticResource BackgroundNormal}" /> 
     <Setter Property="BorderBrush" Value="{StaticResource BorderBrushNormal}" /> 
    </Style> 
</ResourceDictionary> 

和 「Styles.xaml」:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <ResourceDictionary.MergedDictionaries> 
     <ResourceDictionary Source="ButtonStyles.xaml" /> 
    </ResourceDictionary.MergedDictionaries> 

    <Style TargetType="Button" BasedOn="{StaticResource StandartButton}" /> 
</ResourceDictionary> 

而這裏的App.xaml:

<Application x:Class="Ferhad.Wpf.App" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      StartupUri="MainWindow.xaml"> 
    <Application.Resources> 
     <ResourceDictionary> 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary Source="pack://application:,,,/Ferhad.Wpf.SystemStyles;component/Styles.xaml" /> 
      </ResourceDictionary.MergedDictionaries> 
     </ResourceDictionary> 
    </Application.Resources> 
</Application> 

一切都在設計時似乎罰款的MainWindow.xaml,但在運行應用程序時拋出異常:Set property 'System.Windows.ResourceDictionary.Source' threw an exception.

我已經使用了Google,但沒有任何幫助。我試圖改變文件的BuildAction,但這也沒有幫助。

UPDATE:

唯一的例外是在行號 '8' 和線位置 '18'。

和內部的例外是:{"Could not load file or assembly 'Ferhad.Wpf.SystemStyles, Culture=neutral' or one of its dependencies. The system cannot find the file specified.":"Ferhad.Wpf.SystemStyles, Culture=neutral"}

+0

你能後的內部異常和行號作爲它被指向?哪個資源字典引發異常 –

+0

@LeoLuis我有更新的問題。感謝您的幫助。 –

回答

3

你可能忘記從App添加到Core參考,SystemStyles需要Core所以如果構建過程只複製SystemStyles它不具有其Core組裝。

App 
-> SystemStyles 
-> Core 

SystemStyles 
-> Core //Not strictly necessary because the build process does not copy the 
     //reference to the App project anyway and the resources 
     //are not resolved at compile-time 

Core 
- 
+0

它工作。 :))我不知道我是如何做到的? :))無論如何,真的非常感謝。這需要我2個小時。 –

+1

@FarhadJabiyev:你可以說這是構建過程中的一個bug,理論上只有'App-> SystemStyles'&'SystemStyles-> Core'references應該是必需的... –

+0

是的。這是正確的。感謝您的確切解釋。 –

0

嘗試修改此

<ResourceDictionary Source="ButtonStyles.xaml" /> 

<ResourceDictionary Source="pack://application:,,,/Ferhad.Wpf.SystemStyles;component/ButtonStyles.xaml" /> 
+1

這不應該改變任何東西。 –

+0

有時候,資源只會通過一些奇怪的東西找到引用,並拋出一個異常,它無法加載並將其更改爲pack uri源碼。像Image Source uris明確說明只是文件名可能會工作,但更快它會拋出異常並需要包 –