Jerry Nixon on Windows: Does a class have a Dependency Property or not?

Jerry Nixon on Windows

Tuesday, July 19, 2011

Does a class have a Dependency Property or not?

Dependency Properties are pretty darn important in WPF. Sometimes when you are messing with a class, you may want to know if that class has a Dependency Property associated to it. But how?

Like this:

var _PropertyName = "MyClass.MyProp";
var _Markup = System.Windows.Markup.Primitives.MarkupWriter.GetMarkupObjectFor(_MyObject);
var _Properties = _Markup.Properties.Where(x => x.DependencyProperty != null);
var _Property = _Properties.Where(x => x.Name == _PropertyName).FirstOrDefault();
if (_Property != null) { /* has property! */ }