我正在使用共享的ResourceDictionary来定义默认样式,并且与Visual Studio 2008中的XAML Designer存在重大冲突。对于显示XAML设计视图的所有尝试, Key不能为null 。
字典被合并到App.xaml中(供所有窗口使用)并且有许多样式设置控件的默认值,因此它们的定义如下所示没有键。如果向样式添加x:Key属性,则默认情况下不再应用它们。我不想在每个控件上都放置明确的Style子句,但看起来我可能不得不这样做。
<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>
包含堆栈的完整异常错误消息:
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()
答案 0 :(得分:1)
我不确定为什么需要密钥,但您可以尝试以下
<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}">