Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a Binding actually work?

I've been learning WPF for a few months now and I'm curious about one thing. How does a Binding actually work? I mean, what happends, under the hood. I don't expect that anyone here would give a detailed explanation but maybe a good resource or link where to read up on something like this. I've been searching and googling for this but no good hits so far.

I realize that to fully understand this you would probably have to understand most parts of the framework but a little basic understanding would be great.

Thanks

like image 820
ImJames Avatar asked Nov 07 '10 09:11

ImJames


1 Answers

There are two aspects to consider in binding, getting values in to the UI and having the UI be notified of changes in its DataContext.

Basically you can bind almost anything to any POCO object, the object does not need to implement anything special. The restriction with plain objects is the binding target will not be told when the underlying value changes.

Property changes are propogated through one of three mechanisims:

Dependancy Properties : will notify the binding system when its value changes, can also be used for animations.

INotifyPropertyChanged : If the binding is to a property on an object which implements INotifyPropertyChanged, the binding system will look for subscribe to the PropertyChanged event and update the binding target, when this event is raised, property names are sent as Strings.

*Property*Changed events : The last thing bindings will look for is an event with a name the same as the source property and Changed on the end, so a Name property would need to have a public event called NameChanged, this allows WPF to bind to older .net classes such as 1.1.

like image 138
benPearce Avatar answered Sep 25 '22 00:09

benPearce