WPF Window The given Key was not present in the Dictionary
I'm now looking for quite some time for a solution to this, and nothing worked for me until now:
I have a C# console application from which i open an Application in a new Window that i designed using the designer. I made a new solution and copied the window in the new solution and now the designer throws the upper exception. The program itself runs well but the designer simply denies to work.
The code used is:
<Window ...Some Description...>
<DockPanel>...Content...>/DockPanel>
</Window>
In the designer "window" it shows this text:
An Exception was thrown. XamlParseException: The given key was not present in the dictionary.
StackTrace:
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
at System.Windows.Application.LoadComponent(Uri resourceLocator)
The exception location is at the "Window" keyword in the XAML.
If i create a new UserControl in XAML that works fine, only Window seems not to work.
Does someone know how to fix this?
Here's the whole Xaml:
<Window x:Class="Interface_002.ControlWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="600" Width="1000" Title="Steering Wheel Control Window" Loaded="Window_Loaded" Closed="Window_Closed">
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem x:Name="miSaveConfig" Header="_Save Config" Click="miSaveConfig_Click"/>
<MenuItem x:Name="miLoadConfig" Header="_Load Config" Click="miLoadConfig_Click"/>
<Separator/>
<MenuItem x:Name="Exit" Header="_Exit" Click="Exit_Click" />
</MenuItem>
<MenuItem Header="Help">
<MenuItem x:Name="miAbout" Header="About" Click="miAbout_Click"/>
</MenuItem>
</Menu>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="250"/>
<RowDefinition Height="250"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500"/>
<ColumnDefinition Width="500"/>
</Grid.ColumnDefinitions>
<Border Grid.Row="0" Grid.Column="0" BorderThickness="1" BorderBrush="Black">
<Grid>
...Content..
</Grid>
</Border>
<Border Grid.Row="1" Grid.Column="0" BorderThickness="1" BorderBrush="Black">
<Grid>
...Content..
</Grid>
</Border>
<Border Grid.Row="0" Grid.Column="1" BorderThickness="1" BorderBrush="Black">
<Grid>
...Content..
</Grid>
</Border>
<Border Grid.Row="1" Grid.Column="1" BorderThickness="1" BorderBrush="Black">
<Grid>
...Content..
</Grid>
</Border>
</Grid>
</DockPanel>
</Window>
EDIT:
The problem has solved itself in some way... I don't know what exactly was the problem. But after loading the solution on another CP and when i reopened it on the original machine it worked again...
I copied your entire XAML in a newly created WPF app. I removed "..." from the grids and changed x:Class attribute from the Window to the complete namespace+name of the class in my project. It work fine! The problem is somewhere else. Maybe in the code missing in the Grids.
链接地址: http://www.djcxy.com/p/30528.html上一篇: 为什么这个WPF TreeViewItem风格导致交叉线程问题?
下一篇: WPF窗口给定的密钥不存在于字典中