x:在用户控件库中找不到类型

Fly*_*del 15 c# wpf user-controls resourcedictionary

我正在尝试ResourceDictionary在WPF UserControl库项目中创建一个内部.当我添加以下样式时:

<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>
Run Code Online (Sandbox Code Playgroud)

我收到一个错误说:

The type 'x:Type' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
Run Code Online (Sandbox Code Playgroud)

我宣布x为:

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Run Code Online (Sandbox Code Playgroud)

这在我在WPF应用程序项目中创建资源字典时有效,但不在UserControl库项目中创建.知道为什么吗?

kro*_*olk 37

当我编写IE扩展并想要创建WPF用户控件时,这发生在我身上.由于该项目最初不是WPF项目,因此没有引用System.Xaml,添加所述引用修复了该问题.