I’ve often had a need to check whether DependencyProperty holds its default value and surprisingly it is not as easy to find how to do that. So I present IsDefaultValue method:

public bool IsDefaultValue(DependencyObject targetObject, DependencyProperty dp)
    return System.Windows.DependencyPropertyHelper.GetValueSource(targetObject, _
       dp).BaseValueSource == BaseValueSource.Default;

And that’s it!

As bonus, if you look into the BaseValueSource enum you might find other interesting things 😉

Professional looking applications made easy with DotNetBar for WinForms, Silverlight and WPF User Interface components. Click here to find out more.

Related posts:

  1. DotNetBar for WPF with Drag & Drop Framework and Enum Picker Released
  2. DotNetBar 6.0 with Office 2007 style Ribbon Control released
  3. DevComponents 10 Years Anniversary
  4. New Year Schedule View in DotNetBar for WinForms
  5. DotNetBar 6.0 goodness, Part 4, Ribbon MDI Merging