c# - x :Type not found in user control library

标签 c# wpf user-controls resourcedictionary

我正在尝试在 WPF 用户控件库项目中创建一个 ResourceDictionary。当我添加以下样式时:

<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 库项目中创建资源字典时,这会起作用。知道为什么吗?

最佳答案

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

关于c# - x :Type not found in user control library,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12606304/

相关文章:

c# - 有什么方法可以区分 "people user accounts"和 "computer user accounts"吗?

c# - WPF 中作用域 EF Core DbContext 的生命周期

c# - Silverlight 用户控件部分类的继承

java - 在 JavaFX 中切换组件的颜色

通过 CMD 的 Java 命令在 C#.NET 中不起作用

c# - XPath 绑定(bind)以读取 wpf 中的 InnerXml

c# - 在 View 模型和 View 之间使用 MVVM 的 Wpf 数据上下文绑定(bind)

c# - XAML 绑定(bind)到 ViewModel 中的控件

wpf - 将资源字典添加到 wpf 中的用户控件库

c# - 如何获取 DeploymentItem 的名称?