[英]Unable to find MergedDictionaries in app.xaml
我創建了一個WPF應用程序(名為“Ferhad.Wpf”)。 然后我在解決方案中添加了兩個名為“Ferhad.Wpf.Core”和“Ferhad.Wpf.SystemStyles”的類庫。
“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>
但是“Ferhad.Wpf.SystemStyles”中也有“ButtonStyles.xaml”和“Styles.xaml”。 這是“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.
我用谷歌搜索過,但沒有任何幫助。 我試圖更改文件的BuildAction,但這也沒有幫助。
更新:
例外是行號'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"}
您可能忘記添加從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
-
嘗試改變這個
<ResourceDictionary Source="ButtonStyles.xaml" />
至
<ResourceDictionary Source="pack://application:,,,/Ferhad.Wpf.SystemStyles;component/ButtonStyles.xaml" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.