Tag Archives: dependency-property

WPF: Depencency Properties

Dependency Properties allows you to extend a functionality, from MSDN:

A dependency property provides functionality that extends the functionality of a property as opposed to a property that is backed by a field.

It is used to create bindable properties on objects deriving from DependencyObject, for example in controls. It is used all across WPF.

You can use it as well to create your own bindable properties.

For example:

2015-31-13 05-31-24-043

<local:ExtendedButton DisplayInRed="True"
    Content="I'm red" />
<local:ExtendedButton DisplayInRed="False"
    Content="I'm NOT red" />

<local:ExtendedButton DisplayInRed="{Binding TrueValue}"
    Content="I'm red" />

<Separator />
            
<local:ExtendedButton2 DisplayInRed="True"
    Content="I'm red" />
<local:ExtendedButton2 DisplayInRed="False"
    Content="I'm NOT red" />

<!--Error, cannot bind-->
<!--<local:ExtendedButton2 DisplayInRed="{Binding TrueValue}"
    Content="I'm red" />-->

Continue reading

Advertisements