Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# x:在用户控件库中找不到类型_C#_Wpf_User Controls_Resourcedictionary - Fatal编程技术网

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

C# x:在用户控件库中找不到类型,c#,wpf,user-controls,resourcedictionary,C#,Wpf,User Controls,Resourcedictionary,我正试图在WPF UserControl库项目中创建一个ResourceDictionary。添加以下样式时: <Style TargetType="{x:Type Button}"> <Setter Property="Background" Value="{StaticResource ResourceKey=GreyBrush}"/> <Setter Property="BorderBrush" Value="{StaticResource R

我正试图在WPF UserControl库项目中创建一个
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>
我宣布x为:

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

当我在WPF应用程序项目中创建一个资源字典,而不是在UserControl库项目中创建一个资源字典时,这就起作用了。知道为什么吗?

我不同意,这是我从一个确实有效的用户控件中获得的贴花

<UserControl x:Class="RedGreenRefactor.View.TestResultsGraph"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

是否缺少根目录

<ResourceDictionary xmlns="..."
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

,即,你在哪里定义x?除此之外

<Style TargetType="Button">


同样有效。

在我的项目中也有同样的外观问题。通过将目标框架从.NET 3.0切换到4.0,我解决了这个问题。

这发生在我编写IE扩展并希望创建WPF用户控件时。由于该项目最初不是一个WPF项目,因此没有对System.Xaml的引用,添加了上述引用修复了该问题

不知道为什么会发生这种情况,一种解决方法是删除{x:Type}文本,即
TargetType=“Button”
。Silverlight AFAIK中也会发生同样的错误,但并不总是发生。在新创建的(.Net 4.0)WPF用户控制库项目的资源字典中,至少上述样式对我来说很好。我正在使用VS2012 Professional并创建一个.Net 3.5 WPF用户控制库。我在完全相同的上下文中体验FlyingStrudel描述的行为。附加观察:如果您创建一个WPF应用程序来测试新创建的小部件,(a)它在运行时工作(b)在设计时,单击测试窗口的设计图面上的任何位置都会生成NullReferenceException。我的命名空间导入与AlSki描述的完全一样。将UserControl项目框架版本从3.5更改为4导致问题消失。VisualStudio开始正确地将x:Type解析为TypeExtension,如悬停提示所示。然而,该小部件当时无法用于仍然是Framework3.5的测试项目。有趣的是,将小部件改回fw35后,我在XAML设计器和停止提供NRE的测试程序中没有出现错误。这是针对3.5还是4.0库的?我猜4.0是Microsoft.CSharp和System.Xaml实际上不是3.54.5,但您始终可以创建一个新的空wpf并比较任何版本wpf应用程序项目和控件库之间的引用是相同的。这为我修复了它!该项目确实进行了编译,但始终显示错误(特别是生产力工具扩展的解决方案浏览器错误功能)。遇到了相同的问题/解决方案,但罪魁祸首是“System.Presentation”。
<Style TargetType="Button">