gpt4 book ai didi

.net - 无法在 app.xaml 中找到 MergedDictionaries

转载 作者:行者123 更新时间:2023-12-02 05:32:56 26 4
gpt4 key购买 nike

我创建了一个 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' throw an exception。

我用谷歌搜索过,但没有任何帮助。我曾尝试更改文件的 BuildAction,但这也无济于事。

更新:

异常(exception)情况在行号“8”和行位置“18”。

内部异常是:{“无法加载文件或程序集‘Ferhad.Wpf.SystemStyles,Culture=neutral’或其依赖项之一。系统找不到指定的文件。”:“Ferhad。 Wpf.SystemStyles, Culture=neutral"}

最佳答案

您可能忘记添加从 AppCore 的引用,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
-

关于.net - 无法在 app.xaml 中找到 MergedDictionaries,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12130823/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com