我试图在WPF UserControl Library项目中创建ResourceDictionary
。当我添加以下样式:x:在用户控件库中找不到类型
<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 Library项目中。任何想法为什么?
不知道为什么会发生,解决方法是只删除{x:Type}文本,即'TargetType =“Button”'。在Silverlight AFAIK中发生同样的错误。 – Patrick
但并不总是会发生。至少上述样式适用于新创建的(.Net 4.0)WPF用户控件库项目中的资源字典。 – Clemens
我正在使用VS2012 Professional并创建.Net 3.5 WPF用户控制库。 – FlyingStreudel