Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

x:Type not found in user control library

I'm trying to create a ResourceDictionary inside a WPF UserControl Library project. When I add the following style:

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

I get an error saying:

The type 'x:Type' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

I am declaring x as:

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

This works when I create a resource dictionary inside a WPF application project, but not inside a UserControl Library project. Any idea why?

like image 439
FlyingStreudel Avatar asked Sep 26 '12 16:09

FlyingStreudel


3 Answers

This happened to me when I was writing an IE Extension and wanted to create WPF User Controls. Since the project was not originally a WPF project there was no reference to System.Xaml, adding said reference fixed the issue.

like image 175
virtualadrian Avatar answered Nov 09 '22 23:11

virtualadrian


Had the same looking issue in my project. I've solved it by switching Target Framework from .NET 3.0 to 4.0.

like image 34
pizycki Avatar answered Nov 10 '22 00:11

pizycki


I have to disagree, here's my decalaration from a UserControl that does work.

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

Is there any chance that the error is telling you exactly what is wrong? Have you got all the assemblies referenced that you need?

Creating a new WPF application I get the following.

WPF default references

like image 1
AlSki Avatar answered Nov 09 '22 22:11

AlSki