2

I am scratching my head to understand the dependency property.

The queries I do have is as following;

As Depenedency property is declared as static, static means class level property, only single instance would be created and all object would be sharing the same object.

I have a user control and I have added dependency property IsHighlighted to that user control. this dependency property is bind to some view model property and I have registered a callback for dependency property value changes. So, as soon as somebody changes the view model property, dependency properties callback would be invoked and it would start an animation if value is true as it a boolean value.

Now, I have created 5 objects view and when i set the viewmodel property for object1 to true, then animation runs for the last node object5 not for object1. view model's property is non static.

I am confused dependency property would be created for each object or it would be single for all the object.

In case it is single for all the objects, then what would be way to track the changes in the user control property on which I need to run the simulation because for normal CLR property in user control no change handler would be called.

Summary: Dependency properties are created at class level or object level. if it is created at class level as it is declared as static, then what is the way to create a property that is at object level( non-static) but it would not be having any value change callback for normal CLR propety. So How to do that.

Yogesh
  • 3,044
  • 8
  • 33
  • 60
  • may be this answer helps you understand it...http://stackoverflow.com/questions/19441453/why-dependency-properties-in-wpf-has-to-be-static/19441693#19441693 – Nitin Nov 09 '13 at 12:48

1 Answers1

0

When you take a look at how you defined a dependency property you will soon notice that its not a usual static property and that its more of describing the property by setting metadata instead of assigning pure value like you would do with simple usual static property. That metadata is being used inside DependencyObjects (every Control in wpf inherits from DependencyObject even UserControls).

What each DependencyObject does with that metadata is to manage its own value for the dependency property.

That is how object5 only changed the value and not every object.

I hope the pic is now a bit clearer to you.

Btw, I also refer to the link the user nit gave you.

Why dependency properties in WPF has to be Static

Go check it out.

Community
  • 1
  • 1
dev hedgehog
  • 8,698
  • 3
  • 28
  • 55