
{"id":1069,"date":"2012-09-01T02:49:24","date_gmt":"2012-09-01T06:49:24","guid":{"rendered":"http:\/\/www.ikriv.com\/blog\/?p=1069"},"modified":"2012-09-01T02:49:24","modified_gmt":"2012-09-01T06:49:24","slug":"binding-does-not-a-dependency-property-make","status":"publish","type":"post","link":"https:\/\/ikriv.com\/blog\/?p=1069","title":{"rendered":"Binding does not a dependency property make"},"content":{"rendered":"<p>In WPF\/Silverlight we are all accustomed to writing things like <code>Width=\"{Binding foo}\"<\/code> and <code>Text=\"{Binding bar}\"<\/code>. The little <code>Binding<\/code> gremlins then actually access <code>foo<\/code> or <code>bar<\/code> property of the current data context and put its value into <code>Width<\/code> or <code>Text<\/code>.<\/p>\n<p>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 <code>Binding<\/code>, but it did not work. When I wrote <code>&lt;MyClass MyBinding={Binding whatever}\" \/&gt;<\/code> in XAML, the little binding gremlins were there again and attempted to get the value of <code>whatever<\/code> from the current data context, failing miserably. There seemed to be no way to tell them NOT to do that and just return a <code>Binding<\/code> object.<\/p>\n<p>But then it hit me: WPF <code>DataGrid<\/code> columns have a property called <code>Binding<\/code> 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 <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.controls.datagridboundcolumn.aspx\"><code>DataGridBoundColumn<\/code><\/a> class revealed that <code>Binding<\/code> is <b>NOT<\/b> a dependency property, it&#8217;s a regular CLR property.<\/p>\n<p>This simple trick stops the binding gremlins on their tracks, as only a dependency property can be their target. Problem solved! <a style=\"display:none\" href=\"http:\/\/www.codeproject.com\/script\/Articles\/BlogFeedList.aspx?amid=1181663\" rel=\"tag\">CodeProject<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In WPF\/Silverlight we are all accustomed to writing things like Width=&#8221;{Binding foo}&#8221; and Text=&#8221;{Binding bar}&#8221;. The little Binding gremlins then actually access foo or bar property of the current data <a href=\"https:\/\/ikriv.com\/blog\/?p=1069\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[4,12],"tags":[],"class_list":["entry","author-ikriv","post-1069","post","type-post","status-publish","format-standard","category-hack","category-wpf"],"_links":{"self":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1069"}],"version-history":[{"count":0,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1069\/revisions"}],"wp:attachment":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}