#126 – Reacting to a Dependency Property Change Using Binding
November 15, 2010 1 Comment
One way to react to a dependency property’s value changing is by binding the property of one control to the property of another control.
The idea with binding is that there is a source object and property, where the data is coming from, and a target object and property.
Here’s an example where we bind the contents of a Label control to the value of a Slider.
<Slider Name="slider1" Maximum="100" /> <Label Name="lblTest" Content="{Binding ElementName=slider1, Path=Value}"/>
The Label is the target control. We bind its Content property to the Slider control’s Value content. When a user slides the slider, its value will change and the new value will be displayed in the Label.
Pingback: #148 – Property Values Set Using Expressions Overwrite the Base Value « 2,000 Things You Should Know About WPF