{"id":5439,"date":"2014-03-30T21:59:30","date_gmt":"2014-03-30T21:59:30","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-assign-a-property-of-type-control-in-xaml-error-collection-of-common-programming-errors\/"},"modified":"2014-03-30T21:59:30","modified_gmt":"2014-03-30T21:59:30","slug":"how-to-assign-a-property-of-type-control-in-xaml-error-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-assign-a-property-of-type-control-in-xaml-error-collection-of-common-programming-errors\/","title":{"rendered":"How to assign a property of type Control in XAML &#8211; error-Collection of common programming errors"},"content":{"rendered":"<p>When you write a WPF application, you&#8217;d probably want to avoid using <code>x:Reference<\/code>, as it&#8217;s a feature of XAML 2009 which is only available for loose XAML.<\/p>\n<p>Alternatively, you can use binding and its <code>ElementName<\/code> property. But for that to work you&#8217;ll need to make <code>TargetControl<\/code> a dependency property. Then it will look like this:<\/p>\n<p><strong>C#<\/strong><\/p>\n<pre><code>public Control TargetControl\n{\n    get { return (Control)this.GetValue(TargetControlProperty); }\n    set { this.SetValue(TargetControlProperty, value); } \n}\n\npublic static readonly DependencyProperty TargetControlProperty =\n    DependencyProperty.Register(\"TargetControl\",\n                                typeof(Control),\n                                typeof(NumericButtonsControl),\n                                new PropertyMetadata(null));\n<\/code><\/pre>\n<p><strong>XAML:<\/strong><\/p>\n<pre><code>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>When you write a WPF application, you&#8217;d probably want to avoid using x:Reference, as it&#8217;s a feature of XAML 2009 which is only available for loose XAML. Alternatively, you can use binding and its ElementName property. But for that to work you&#8217;ll need to make TargetControl a dependency property. Then it will look like this: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5439","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5439","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5439"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5439\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}