{"id":672,"date":"2013-07-31T13:58:14","date_gmt":"2013-07-31T13:58:14","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=672"},"modified":"2013-08-02T09:26:22","modified_gmt":"2013-08-02T09:26:22","slug":"templatebinding-can-be-a-little-too-lightweight","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/templatebinding-can-be-a-little-too-lightweight\/","title":{"rendered":"TemplateBinding can be a little too lightweight"},"content":{"rendered":"<p>TemplateBinding can be used within a ControlTemplate to reference a value from the control that the template has been implemented on, but it has a few issues associated with it.<\/p>\n<p><strong>On the plus side<\/strong><\/p>\n<p>TemplateBinding is evaluated at compile time giving an increase in performance. <\/p>\n<p><strong>On the negative side<\/strong><\/p>\n<p>TemplateBinding is a little lightweight on features and in what it can bind to or more specifically how it&#8217;s binds. It doesn&#8217;t offer all the capabilities of the Binding, for example you cannot apply converters, it doesn&#8217;t support two-way binding and most importantly it doesn&#8217;t handle the type converting that Binding implements. <\/p>\n<p>So for example <\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;TextBlock Text=&quot;{TemplateBinding MyInteger}&quot; \/&gt;\r\n<\/pre>\n<p>where (you guessed it) MyInteger is an int, nothing will be output in this TextBlock. As it cannot convert an int to a string.<\/p>\n<p>Luckily there&#8217;s another way of binding to the template using the slightly more verbose TemplatedParent option<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;TextBlock Text=&quot;{Binding MyInteger, RelativeSource={RelativeSource TemplatedParent}}&quot; \/&gt;\r\n<\/pre>\n<p>Unlike the TemplateBinding this is evaluated at runtime and by using the Binding class we can all the goodness associated with Binding.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TemplateBinding can be used within a ControlTemplate to reference a value from the control that the template has been implemented on, but it has a few issues associated with it. On the plus side TemplateBinding is evaluated at compile time giving an increase in performance. On the negative side TemplateBinding is a little lightweight on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[13],"tags":[],"class_list":["post-672","post","type-post","status-publish","format-standard","hentry","category-wpf"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/672","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=672"}],"version-history":[{"count":4,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/672\/revisions"}],"predecessor-version":[{"id":683,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/672\/revisions\/683"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=672"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}