title: Strange behavior for WPF attached property and binding
body: <p>I am trying to register an WPF attached property on a grid control, however, I met very strange behavior today:</p>
  
  <pre><code>public static class MyClass
  {
      public static readonly DependencyProperty MyPropertyProperty =
          DependencyProperty.RegisterAttached("MyProperty", typeof(string),
          typeof(MyClass), null);
  
      public static string GetMyProperty(DependencyObject d)
      {
          return (string)d.GetValue(MyPropertyProperty);
      }
  
      public static void SetMyProperty(DependencyObject d, string value)
      {
          d.SetValue(MyPropertyProperty, value); //&lt;-- set breakpoint here
      }
  }
  </code></pre>
  
  <p>XAML:</p>
  
  <pre><code>&lt;GridControl local:MyClass.MyProperty="My Name"&gt;
  ...
  &lt;/GridControl&gt;
  </code></pre>
  
  <p>when I wrote like this, the attached property's setter never gets executed. and value never be set. but I can snoop into the grid and found the attached property is attached with an empty value.</p>
  
  <p>but when I change the attached property name to:</p>
  
  <pre><code>    public static readonly DependencyProperty MyPropertyProperty =
          DependencyProperty.RegisterAttached("xxxMyProperty", typeof(string),
          typeof(MyClass), null);
  </code></pre>
  
  <p>i.e. use a different name other than MyProperty. then the breakpoint can be hit! and value can be set! </p>
  
  <p>Moreover, when I change the attached property as:</p>
  
  <pre><code>    public static readonly DependencyProperty MyPropertyProperty =
          DependencyProperty.RegisterAttached("MyProperty", typeof(string),
          typeof(UIElement), null);
  </code></pre>
  
  <p>i.e. change the owner type to UIElement, then I can also hit the breakpoint, just wondering why?</p>
  
  <p>However, when I setup a binding in XAML instead of a string constant, each case above will got an exception saying <code>A 'Binding' can only be set on a DependencyProperty of a DependencyObject</code></p>
  
  <p>Binding XAML example:</p>
  
  <pre><code>&lt;GridControl local:MyClass.MyProperty="{Binding MyStringValue}"&gt;
  ...
  &lt;/GridControl&gt;
  </code></pre>
  
  <p>Does anyone met this strange behavior before? What am I missing in my case? Thanks in advance for the reply!</p>