VS2008 Исключение конструктора XAML «Ключ не может быть пустым» при использовании стилей по умолчанию из ResourceDictionary - PullRequest
1 голос
/ 03 февраля 2010

Я использую общий ResourceDictionary для определения стилей по умолчанию и имею серьезные конфликты с XAML Designer в Visual Studio 2008. Ключ не может быть нулевым появляется для всех попыток показать представление дизайна XAML.

Словарь объединяется в 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()

1 Ответ

1 голос
/ 03 февраля 2010

Я не уверен, почему для этого потребуется ключ, но вы можете попробовать следующее

<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}">
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...