Sandrino Di Mattia

Content-type: Microsoft

Social

Follow me on Twitter! LinkedIn! RSS! SilverlightShow Contributor

Recent posts

Tags

Categories

Archive

Blogroll

Set the default value of a dependency property

While creating a new control I wanted to set the value of a bool DependencyProperty to true.
I hoped to use [DefaultValue] on the property that invokes the DependencyProperty but this dit not work.

And it's not abnormal that this didn't work.
WPF does not go through the getters/setters, it talks to the DependencyProperty directly.

So after searching a little bit I found the following:

public static DependencyProperty IsFilteringCaseSensitiveProperty =
     DependencyProperty.Register("IsFilteringCaseSensitive", typeof(bool), typeof(FilteringDataGrid), new PropertyMetadata(
true));

You have to add the default value in the PropertyMetadata of your dependency property.

Posted: Aug 05 2009, 11:53 by Sandrino | Comments (0) RSS comment feed |
Filed under: Development