【发布时间】:2017-02-25 07:54:35
【问题描述】:
有人可以帮我解决这个问题吗,我想我已经正确编码了所需的密钥。这是一个样式应用程序字典测试,只有一个按钮。有两个错误消息:每个字典条目必须有一个关联的键,并且所有添加到 IDictionary 的对象都必须有一个 Key 属性或与之关联的其他某种类型的键。第 13 行位置 14,均用于 MainWINdow.xaml。
此项目中没有程序员编写的代码。
这是 MainWindow.xaml 代码:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary Source="App.xaml" /> This is the offending line
</ResourceDictionary>
</Window.Resources>
<Grid>
<Button Style="{StaticResource algo}" />
</Grid>
这是 App.xaml 代码:
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style x:Key="algo" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Red" />
</Style>
</Application.Resources>
【问题讨论】:
-
违规行应该在
ResourceDictionary.MergedDictionaries内。否则它将被视为字典中的条目。 Documentation