VS2008 XAML 设计器异常“密钥不能为空"使用 ResourceDictionary 中的默认样式时 [英] VS2008 XAML Designer exception "Key cannot be null" when using default styles from a ResourceDictionary

查看:25
本文介绍了VS2008 XAML 设计器异常“密钥不能为空"使用 ResourceDictionary 中的默认样式时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用共享的 ResourceDictionary 来定义默认样式,并且与 Visual Studio 2008 中的 XAML 设计器存在重大冲突.键不能为空出现在所有尝试显示 XAML 设计视图的情况下.

I'm using a shared ResourceDictionary to define default styles and having major conflicts with the XAML Designer in Visual Studio 2008. Key cannot be null appears for all attempts to show the XAML design view.

字典被合并到 App.xaml(供所有窗口使用)中,并且有许多样式设置控件的默认值,因此它们的定义如下所示没有键.如果向样式添加 x:Key 属性,则默认情况下不再应用它们.我不想在每个控件上都放置明确的 Style 子句,但看起来我可能不得不这样做.

The dictionary is merged into App.xaml (to be used by all windows) and has a number of styles setting the defaults for controls, so they are defined as shown below without a key. If you add an x:Key attribute to the styles, they are no longer applied by default. I don't want to have to put explicit Style clauses on every control but it looks like I might have to.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="windowStyle" TargetType="{x:Type Window}">
        <Setter Property="Background" Value="LightGray" />
    </Style>
    <Style TargetType="{x:Type TextBox}">
        <Setter Property="Background" Value="AliceBlue" />
        <Setter Property="Height" Value="23" />
    </Style>
</ResourceDictionary>

带有堆栈的完整异常错误消息:

The full exception error message with stack:

Key cannot be null.
Parameter name: key
   at System.Collections.Hashtable.get_Item(Object key)
   at MS.Internal.Xaml.AssemblyNode.For(Assembly assembly, Boolean includeInternal)
   at MS.Internal.Xaml.ReflectionProjectNode.LoadAssembly(AssemblyName name, Boolean includeInternal)
   at MS.Internal.Xaml.ReflectionProjectNode.BuildAssemblies()
   at MS.Internal.Xaml.ReflectionProjectNode.BuildSubsumption()
   at MS.Internal.Xaml.ReflectionProjectNode.SubsumingNamespace(Identifier identifier)
   at MS.Internal.Xaml.XmlElement.BuildScope(PrefixScope parentScope, IParseContext context)
   at MS.Internal.Xaml.XmlElement.FindElementType(PrefixScope parentScope, IParseContext context)
   at MS.Internal.DocumentTrees.Markup.XamlSourceDocument.get_RootType()
   at Microsoft.Windows.Design.Documents.Trees.MarkupDocumentTreeManager.get_RootType()
   at Microsoft.Windows.Design.Documents.MarkupDocumentManager.CalculateLoadErrorState()
   at Microsoft.Windows.Design.Documents.MarkupDocumentManager.get_LoadState()
   at MS.Internal.Host.PersistenceSubsystem.Load()
   at MS.Internal.Host.Designer.Load()
   at MS.Internal.Designer.VSDesigner.Load()
   at MS.Internal.Designer.VSIsolatedDesigner.VSIsolatedView.Load()
   at MS.Internal.Designer.VSIsolatedDesigner.VSIsolatedDesignerFactory.Load(IsolatedView view)
   at MS.Internal.Host.Isolation.IsolatedDesigner.BootstrapProxy.LoadDesigner(IsolatedDesignerFactory factory, IsolatedView view)
   at MS.Internal.Host.Isolation.IsolatedDesigner.BootstrapProxy.LoadDesigner(IsolatedDesignerFactory factory, IsolatedView view)
   at MS.Internal.Host.Isolation.IsolatedDesigner.Load()
   at MS.Internal.Designer.DesignerPane.LoadDesignerView()

推荐答案

我不知道为什么需要密钥,但您可以尝试以下操作

I'm not sure why it would require a key, but you can try the following

<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}">

这篇关于VS2008 XAML 设计器异常“密钥不能为空"使用 ResourceDictionary 中的默认样式时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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