我試圖在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