Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi Guys ,

I am extending Image Control in WPF.
I am developing a card game an this control will be my Card.

I noticed when i create my WPF Custom Control that even if my Generic.xaml sets Width = 132 and Height = 132 when i drag my Card Control from the toolbox it is rendered with Width = 200 and Height = 150.

I have already tried OverrideMetada on my static constructor and nothing works.

What is happening ?

Here is my class ...
XML
<public class Retrato : Image
{
    static Retrato()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(Retrato), new FrameworkPropertyMetadata(typeof(Retrato)));
        
        // I have already tried this ...
        //OverridesDefaultStyleProperty.OverrideMetadata(typeof(Retrato), new FrameworkPropertyMetadata(true));

        // I have already tried this ... It only works when you instance an object ...
        //WidthProperty.OverrideMetadata(typeof(Retrato), new FrameworkPropertyMetadata(90d));
    }
};




Here is my Generic.Xaml

XML
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:SixtyOne">


    <Style TargetType="{x:Type local:Retrato}">
        <Setter Property="OverridesDefaultStyle" Value="true" />
        <Setter Property="Width" Value="132" />
        <Setter Property="Height" Value="132" />
        <Setter Property="VerticalAlignment" Value="Top" />
        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="Stretch" Value="Fill" />
    </Style>
</ResourceDictionary>
Posted
Updated 23-Dec-11 11:52am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900