in

DĂ© specialist in .NET trainingen en consultancy

Jo-wen Mei

Check some (runtime) characteristics of a dependency property

 

It's pretty easy to inherit from an existing control in WPF.

For instance, this great programmer I know has written an extended combobox. It has extra functionality, like:

* Automatically select the value if only one item is available in the items source;

* Disable the control when no items are in the items source;

So, there's logic in the inherited class that manages the IsEnabled property.

Flexibility must remain, so consumers of this control should still be able to set the IsEnabled property, and overrule the default logic.

Here's a way to programmatically check if the property has been set:

if (DependencyPropertyHelper.GetValueSource(this, ComboBox.IsEnabledProperty).BaseValueSource == BaseValueSource.Default)

{

      IsEnabled = !(IsDisabledWhenItemsSourceIsEmpty && (_customItemsSource.Count == 0));

}

More info

Published dec 11 2009, 05:52 by Jo-wen
Filed under:

Comments

No Comments