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'."}
1

1 Answer 1

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));
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for help, i don't know how i miss that :(
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 ;)
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 on MSDN.
That was just an example :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.