首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在MergedDictionaries中找到app.xaml

无法在MergedDictionaries中找到app.xaml
EN

Stack Overflow用户
提问于 2012-08-26 14:15:36
回答 2查看 1.6K关注 0票数 2

我已经创建了一个WPF应用程序(名为"Ferhad.Wpf")。然后,我在解决方案中添加了两个类库,名称为"Ferhad.Wpf.Core“和"Ferhad.Wpf.SystemStyles”。

在"Resources.xaml“中只有"Ferhad.Wpf.Core”。

代码语言:javascript
复制
<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":

代码语言:javascript
复制
<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":

代码语言:javascript
复制
<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:

代码语言:javascript
复制
<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"}

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-08-26 15:16:43

您可能忘记添加从AppCore的引用,SystemStyles需要Core,所以如果构建过程只复制SystemStyles,则没有Core程序集。

代码语言:javascript
复制
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
-
票数 4
EN

Stack Overflow用户

发布于 2012-08-26 15:26:20

试着改变这个

代码语言:javascript
复制
    <ResourceDictionary Source="ButtonStyles.xaml" />

代码语言:javascript
复制
  <ResourceDictionary Source="pack://application:,,,/Ferhad.Wpf.SystemStyles;component/ButtonStyles.xaml" />
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12130823

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档