title: WPF Attached Property Data Binding
body: <p>I try to use binding with an attached property. But can't get it working.</p>
  
  <pre><code>public class Attached
  {
      public static DependencyProperty TestProperty =
          DependencyProperty.RegisterAttached("TestProperty", typeof(bool), typeof(Attached),
          new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Inherits));
  
      public static bool GetTest(DependencyObject obj)
      {
          return (bool)obj.GetValue(TestProperty);
      }
  
      public static void SetTest(DependencyObject obj, bool value)
      {
          obj.SetValue(TestProperty, value);
      }
  }
  </code></pre>
  
  <p>The XAML Code:</p>
  
  <pre><code>&lt;Window ...&gt;
      &lt;StackPanel local:Attached.Test="true" x:Name="f"&gt;
          &lt;CheckBox local:Attached.Test="true" IsChecked="{Binding (local:Attached.Test), Mode=TwoWay, RelativeSource={RelativeSource Self}}" /&gt;
          &lt;CheckBox local:Attached.Test="true" IsChecked="{Binding (local:Attached.Test), Mode=TwoWay}" /&gt;
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>And the Binding Error:</p>
  
  <pre><code>System.Windows.Data Error: 40 : BindingExpression path error: '(local:Attached.Test)' property not found on 'object' ''StackPanel' (Name='f')'. BindingExpression:Path=(local:Attached.Test); DataItem='StackPanel' (Name='f'); target element is 'CheckBox' (Name=''); target property is 'IsChecked' (type 'Nullable`1')
  </code></pre>