Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get default value for DependencyProperty

I have issue to set all controls values by button click to default. Problem that this is not working when style is set.

For example i have code:

               var metadata = dependencyProperty.DefaultMetadata;

                if (value == null)
                {
                    return metadata.DefaultValue == value;
                }
                else
                {
                    return value.Equals(metadata.DefaultValue);
                }

But this is not actually default properties! Because in styles can be other values set! How to get really "default" proprties for control!? So WPF will also return value from style if such is set?

P.s. ClearValue(propertyToClear); cannot be used because in some cases i need to check values.

like image 371
Ievgen Avatar asked Dec 09 '22 22:12

Ievgen


1 Answers

There might be different metadata for different dependency object types. Hence you would have to get the property metadata for a specific type by one of the GetMetadata overloads.

var metadata = dependencyProperty.GetMetadata(typeof(SomeDependencyObject));
var defaultValue = metadata.DefaultValue;
like image 102
Clemens Avatar answered Dec 29 '22 10:12

Clemens