2012-09-26 3 views
13

ResourceDictionary을 WPF UserControl Library 프로젝트 내에 생성하려고합니다. 나는 다음과 같은 스타일을 추가 할 때 :x : 사용자 정의 라이브러리에 유형이 없습니다.

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를 선언하고있다 :

<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> 

을 내가 말하는 오류가

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

나는 내부 리소스 사전을 만들 때이 작동 WPF 응용 프로그램 프로젝트, UserControl Library 프로젝트에는 없습니다. 왜 그런가?

+0

왜 그런지 알 수 없으므로 해결 방법은 {x : Type} 텍스트 즉 'TargetType = "Button"'을 제거하는 것입니다. Silverlight AFAIK에서 같은 오류가 발생합니다. – Patrick

+0

하지만 항상 그런 것은 아닙니다. 위 스타일은 새로 생성 된 (.Net 4.0) WPF User Control Library 프로젝트의 리소스 사전에서 나에게 잘 작동합니다. – Clemens

+0

VS2012 Professional을 사용하고 .NET 3.5 WPF 사용자 정의 라이브러리를 만듭니다. – FlyingStreudel

답변

31

IE Extension을 작성하고 WPF 사용자 컨트롤을 만들고 싶을 때 이런 일이 일어났습니다. 프로젝트가 원래 WPF 프로젝트가 아니기 때문에 System.Xaml에 대한 참조가 없었으며, 참조가 추가되어이 문제가 해결되었습니다.

+1

이것은 나에게 그것을 고쳤다! 프로젝트가 컴파일되었지만 항상 오류를 표시했습니다 (특히 Productivity Power Tools 확장의 솔루션 탐색기 오류 기능을 사용하는 경우). – yourbuddypal

+1

동일한 문제/해결 방법이 있지만 그 원인은 "System.Presentation"입니다. –

1

동의하지 않으면, 여기에 내 Decalaration 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" 

무엇이 잘못 되었습니까? 필요한 어셈블리를 모두 참조 했습니까?

새 WPF 응용 프로그램을 만들면 다음과 같은 결과가 발생합니다.

WPF default references

+0

3.5 또는 4.0 라이브러리 용입니까? 나는 Microsoft와 마찬가지로 4.0을 추측하고있다 .CSharp와 System.Xaml은 3이 아니다.5 – FlyingStreudel

+0

4.5 실제로,하지만 당신은 항상 새로운 빈 wpf를 만들고 어떤 버전이든지 비교할 수 있습니다 – AlSki

+0

참조는 wpf 앱 프로젝트와 컨트롤 라이브러리간에 동일합니다. – FlyingStreudel

-1

당신은 즉 위치를 X를 정의 할 루트

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

누락? 그 외에도

<Style TargetType="Button"> 

도 사용할 수 있습니다.

2

내 프로젝트에서 같은 문제가 발생했습니다. Target Framework를 .NET 3.0에서 4.0으로 바꾸어서 해결했습니다.

관련 문제