0

I am trying to define a dependency property like this:

public static readonly DependencyProperty DependencyPropertyName= DependencyProperty.Register("DepName", typeof(EnumName), typeof(MyWindow1), new FrameworkPropertyMetadata("FrameWorkProperty", FrameworkPropertyMetadataOptions.AffectsRender, Target));

private static void Target(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
    //some logic here
}

public EnumName DepName
{
    get { return (EnumName)GetValue(DependencyPropertyName); }
    set { SetValue(DependencyPropertyName, value); }
}

And i get this error, and dont understand why:

{"Default value type does not match type of property 'DepName'."}
Rock3rRullz
  • 357
  • 1
  • 4
  • 21
  • This may help: http://stackoverflow.com/questions/20398751/the-default-value-type-does-not-match-the-type-of-the-property – Behrad Farsi Feb 13 '14 at 08:26

1 Answers1

1

The default value type (String) of your Dependency Property does not match the Type of your property DepName (EnumName).

Change the default type in your dependency property and it should work.

public static readonly DependencyProperty DependencyPropertyName= DependencyProperty.Register(
    "DepName", 
    typeof(EnumName), 
    typeof(MyWindow1), 
    new FrameworkPropertyMetadata(
        EnumName.SomeValue, // this is the defalt value
        FrameworkPropertyMetadataOptions.AffectsRender, 
        Target));
Eirik
  • 4,135
  • 27
  • 29
  • Thank you for help, i don't know how i miss that :( – Rock3rRullz Feb 13 '14 at 08:45
  • It's easy to go blind on your own code from time to time. All you need is to get away from your code a bit and get back with fresh eyes. Lunch usually does the trick for me ;) – Eirik Feb 13 '14 at 09:26
  • 1
    Please note also that there are naming conventions for dependency property identifier fields. Yours should be called `DepNameProperty` instead of `DependencyPropertyName`. Please see the *Dependency Property Name Conventions* section in [Checklist for Defining a Dependency Property](http://msdn.microsoft.com/en-us/library/ms753358.aspx#checklist) on MSDN. – Clemens Feb 13 '14 at 10:26
  • That was just an example :) – Rock3rRullz Feb 13 '14 at 13:14