Click here to Skip to main content
13,087,235 members (70,076 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 3 Sep 2012

Binding does not a dependency property make

, 3 Sep 2012
Rate this:
Please Sign up or sign in to vote.
This simple trick stops the binding gremlins on their tracks, as only a dependency property can be their target.

In WPF/Silverlight we are all accustomed to writing things like Width="{Binding foo}" and Text="{Binding bar}". The little Binding gremlins then actually access foo or bar property of the current data context and put its value into Width or Text.

But last night I ran into a nasty problem: what if I wanted to capture the binding itself, to apply it later in a different data context? I tried to create a dependency property of type Binding, but it did not work. When I wrote <MyClass MyBinding={Binding whatever}" /> in XAML, the little binding gremlins were there again and attempted to get the value of whatever from the current data context, failing miserably. There seemed to be no way to tell them not to do that and just return a Binding object.

But then it hit me: WPF DataGrid columns have a property called Binding that does exactly what I needed: it grabs a binding from XAML and then applies it to the data items of the grid one by one. Careful examination of the DataGridBoundColumn class revealed that Binding is NOT a dependency property, it’s a regular CLR property.

This simple trick stops the binding gremlins on their tracks, as only a dependency property can be their target. Problem solved!


This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


About the Author

Ivan Krivyakov
Technical Lead Thomson Reuters
United States United States
Ivan is a hands-on software architect/technical lead working for Thomson Reuters in the New York City area. At present I am mostly building complex multi-threaded WPF application for the financial sector, but I am also interested in cloud computing, web development, mobile development, etc.

Please visit my web site:

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170813.1 | Last Updated 3 Sep 2012
Article Copyright 2012 by Ivan Krivyakov
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid