Friday, September 3, 2010

How to set a binding on a DependencyObject from code.

Sometimes it is useful to be able to set bindings on DependencyObjects in code.  If the object you are working in derives from FrameworkElement you can just use the object’s SetBinding method, but what if the object is derived from something else such as a Freezable?

The answer is that you use the static BindingOperations classes' SetBinding method, which unsurprisingly is what the implementation of SetBinding on FrameworkElement calls to do its work anyway.

No comments:

Post a Comment