This might be a stupid question.
- Dependency properties are static in nature.
- Button (which is basically a public class) has somany dependnency properties.
If I use two button in my window, that means different instances of same class…but the static property should be only one. If I change Dependency property of one button change, other should also be changed, right ?
Thanks
Anish
A DependencyProperty is not the same as a regular property. It is a property definition that depends on another property to get it’s value. It’s not meant to contain a value, but instead contains a pointer to another value.
If you do something like
<TextBlock Text="Test" />, you are pointing the value of the Text DepdencyProperty to a string value which says “Test”. If you do<TextBlock Text="{Binding UserName}" />, you are pointing the value to a property on the TextBlock’s DataContext (usually a class) calledUserName.I actually wrote something here about how DependencyProperties differ from regular properties if you’re interested