我正在尝试ResourceDictionary
在 WPF 用户控件库项目中创建一个。当我添加以下样式时:
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="{StaticResource ResourceKey=GreyBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource ResourceKey=LightBlueBrush}"/>
<Setter Property="BorderThickness" Value="1"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource ResourceKey=OrangeBrush}"/>
</Trigger>
<EventTrigger RoutedEvent="Click">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color" To="{StaticResource ResourceKey=LightOrange}" Duration="0:0:.1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
我收到一条错误消息:
The type 'x:Type' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
我将 x 声明为:
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
这适用于我在 WPF 应用程序项目中创建资源字典,但不是在 UserControl 库项目中。知道为什么吗?