Answer the question
In order to leave comments, you need to log in
How does binding to a dependency property property work?
Hello!
I just recently started working with WPF and had a question that I could not find the answer to in the textbooks.
I have a control that allows you to set a set of properties for one object. As I've read in tutorials, for two-way communication to work, the properties of that object need to be dependency properties, and in the xaml, you just need to use a markup extension to link to those properties. But I did it a little differently, I declared the whole object as a dependency property. I don't know why, but it works. When I change any of the properties of this object in the interface - the system understands this and updates the view. Those. once again:
1. There is a UserControl. It stores a dependency property whose type is class A.
2. In this control, in the XAML code, I bind the properties of class A to the text boxes.
3. To check, in the control I add a label that displays the value of one of the properties.
4. When I change the value in the textbox, the label is also updated.
Question: How does the system know that I have changed a property that is not a dependency property?
Answer the question
In order to leave comments, you need to log in
INotyfyPropertyChanged, roughly speaking, it is necessary to implement this interface in the binding object, when changing properties, it is necessary to call the PropertyChangedEventHandler event, which notifies the property to which the binding is about changing the binding object. DependencyProperty implements this interface. In a word, if we write like this
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question