WPF MergedDictionaries - 值不能为空 - 参数名称:项目 [英] WPF MergedDictionaries - Value Cannot be Null - Parameter Name: item

查看:25
本文介绍了WPF MergedDictionaries - 值不能为空 - 参数名称:项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 App.Resources MergedDictionary 遇到了一个烦人的问题.每次从另一个程序集中添加一个带有源代码和 XML 命名空间的新字典时,都会产生错误并且我无法构建我的程序.

I am having a nagging issue with my App.Resources MergedDictionary. Every time add a new dictionary with a source and XML namespace from another assembly, an error is produced and I cannot build my program.

错误出现在 App.xaml 中,带有下划线的 ResourceDictionary 和消息 Value 不能为 Null.参数名称:item.这完全没有意义,因为我以前做过完全相同的事情.唯一的区别是这一次,我引用了另一个程序集(c# 类库)的命名空间.这是 App.xaml 文件:

The error appears in App.xaml with the ResourceDictionary underlined and the message Value Cannot be Null. Parameter Name: item. This makes absolutely no sense as I have done the exact same thing before. The only difference is that this time, I am referencing the namespace of another assembly(c# class library). Here is the App.xaml file:

<Application x:Class="Quiz.Client.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:Quiz.Client"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/Styles.xaml" />
                <ResourceDictionary Source="Resources/Templates.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

下面是 Styles.xaml:

Below is Styles.xaml:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Quiz.Client">

    <Style x:Key="StrongFont"
           TargetType="ContentControl">
        <Setter Property="FontSize"
                Value="20" />
        <Setter Property="FontWeight"
                Value="ExtraBold" />
        <Setter Property="Foreground"
                Value="DarkRed" />
    </Style>


</ResourceDictionary>

这里是 Templates.xaml:

Here is Templates.xaml:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Quiz.Client"
                    xmlns:domain="clr-namespace:Quiz.Core.Domain;assembly=Quiz.Core"
                    xmlns:common="clr-namespace:Quiz.Client.Common">

    <DataTemplate x:Key="ArithmeticQuestionTemplate"
                  DataType="domain:ArithmeticQuestion">

    </DataTemplate>

    <common:QuestionTemplateSelector x:Key="QuestionTemplateSelector"
                                     ArithmeticTemplate="{StaticResource ArithmeticQuestionTemplate}" />

</ResourceDictionary>

这到底是怎么回事?是否引入了破坏软件的更改或其他内容?我完全迷失了.

What the heck is going on? Was there a software-breaking change introduced or something? I am completely lost.

推荐答案

确认!!!此错误由 Microsoft 跟踪.这意味着 WPF 在某些方面将尝试通过 Microsoft 报告过程自动向 Microsoft 报告.在报告 VS 期间开始冻结.请等待错误报告完成.

Confirm!!! This bug is tracked by Microsoft. This mean WPF in some points will is trying to report to Microsoft automatically with Microsoft report process. During the report VS start freeze. Please, wait bug report to finish.

该bug在lattes VS 2019中依然存在.

The bug still exist in lattes VS 2019.

重启后一切正常.确认!!!

After restart everything is fine. Confirm!!!

感谢您的回答.我相信这是由未知原因引起的 Visual Studio 错误.也许我的插件之一,谁知道.解决问题的唯一方法是重新启动 Visual Studio 并构建项目.从另一个程序集中添加新命名空间时,问题似乎开始了.然后,在重新启动 Visual Studio 之前无法构建项目.很奇怪,以前从来没有见过这样的东西.– 用户3096803

Thanks for the answer. I believe it is a Visual Studio bug caused by something unknown. Maybe one of my plugins, who knows. The only thing that fixes the issue is restarting visual studio and building the project. The problem seems to begin when adding a new namespace from another assembly. The project then can't build until visual studio is restarted. Very weird, never seen anything like it before. – user3096803

这篇关于WPF MergedDictionaries - 值不能为空 - 参数名称:项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆