我已經創建了一個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"}
你能後的內部異常和行號作爲它被指向?哪個資源字典引發異常 –
@LeoLuis我有更新的問題。感謝您的幫助。 –