我的 App.Resources MergedDictionary 遇到了一个棘手的问题。每次添加带有来自另一个程序集的源和 XML 命名空间的新字典时,都会产生错误,并且我无法构建我的程序。
该错误出现在 App.xaml 中,并带有下划线的 ResourceDictionary 和消息Value Cannot be Null. Parameter Name: item
。这完全没有意义,因为我以前也做过同样的事情。唯一的区别是,这次我引用了另一个程序集(c# 类库)的命名空间。这是 App.xaml 文件:
<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:
<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:
<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>
到底他妈发生了什么?是否引入了软件破坏性更改或其他内容?我完全迷失了。
确认!!! Microsoft 已跟踪此错误。这意味着 WPF 在某些方面将尝试通过 Microsoft 报告进程自动向 Microsoft 报告。报告期间VS开始冻结。请等待错误报告完成。
该错误在拿铁 VS 2019 中仍然存在。
重启后一切正常。确认!!!
感谢你的回答。我相信这是由未知原因引起的 Visual Studio 错误。也许是我的插件之一,谁知道呢。解决该问题的唯一方法是重新启动 Visual Studio 并构建项目。当从另一个程序集中添加新的命名空间时,问题似乎就开始了。然后,在 Visual Studio 重新启动之前,无法构建该项目。非常奇怪,以前从未见过这样的事情。 – 用户3096803
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)