Pages

Friday, March 8, 2013

Two way data binding on a DependencyProperty

I was creating a WPF UserControl today which (among other things) was exposing a DependencyProperty for use in data binding. The problem I came across was that it didn't bind two-way by default and for a while I couldn't figure out either why nor what was the most slick way to go about it.

So here is the trick in case anyone stumbles upon this post while facing a similar problem. In the metadata for your DependencyProperty, don't forget to set the BindsTwoWayByDefault property to true.