title: Bind to dependency property defined in derived class in XAML
body: <p>I have a simple view derived from Window. In the code behind file for that derived class I define a new DependencyProperty called ActiveDocument.</p>
  
  <p>I wish to bind this new DependencyProperty to a property on the ViewModel which is set as the view's DataContext.</p>
  
  <p>I can set this binding using code in the classes constructor, but attempting to bind the property in the XAML file causes an error message saying that the property ActiveDocument cannot be found on class Window.</p>
  
  <p>What is the correct syntax for doing this in XAML?</p>
  
  <p>[Update with code]</p>
  
  <p><strong>MainWindowViewModel.cs</strong></p>
  
  <pre><code>class MainWindowViewModel
  {
      public bool IWantBool { get; set; }
  }
  </code></pre>
  
  <p><strong>MainWindow.xaml.cs</strong></p>
  
  <pre><code>public partial class MainWindow : Window
  {
      public MainWindow()
      {
          DataContext = new MainWindowViewModel();
          InitializeComponent();
      }
  
      public static readonly DependencyProperty BoolProperty = DependencyProperty.Register(
          "BoolProperty", typeof(bool), typeof(MainWindow));
  }
  </code></pre>
  
  <p><strong>Mainwindow.xaml</strong></p>
  
  <pre><code>&lt;Window x:Class="DependencyPropertyTest.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:DependencyPropertyTest"
  
      &lt;!-- ERROR: BoolProperty not found on type Window. --&gt;
      BoolProperty="{Binding path=IWantBool}"
  
      &lt;!-- ERROR: Attachable property not found in type MainWindow. --&gt;
      local:MainWindow.BoolProperty="{Binding path=IWantBool}"&gt;
  
      &lt;Grid&gt;
  
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>