title: WPF Bind DependencyProperty to another DependencyProperty
body: <p>I have a TreeView within a UserControl, which is able to Scroll + Zoom and Drag. (Because the TreeView is really huge) Because the Scroll/Zoom/Drag UserControl is listening to</p>
  
  <ol>
  <li>OnScrollViewerScrollChanged </li>
  <li>OnMouseLeftButtonUp </li>
  <li>OnMouseLeftButtonUp</li>
  <li>OnPreviewMouseWheel </li>
  <li>OnMouseLeftButtonDown </li>
  <li>OnMouseMove</li>
  </ol>
  
  <p>the TreeViewItems are not able to receive any mouse input. Therefore, I created a DependencyProperty for a TreeViewItem, so called IsMouseHover. That DP toggles between true and false, if the mouse enters or leaves the TreeViewItem.</p>
  
  <p>The ScrollZoomDrag UserControl also has a DP, so called "Active", which subscribes or unsubscribes all the mentioned events above.</p>
  
  <p>Now I would like to bind the TreeViewItem's "IsMouseHover" to the ScrollZoomDrag's Control "Active" DP.</p>
  
  <pre><code>    &lt;controls:ScrollDragZoomControl&gt;
      &lt;controls:OrgTreeView ItemsSource="{Binding Root}"&gt;
          &lt;controls:OrgTreeView.ItemTemplate&gt;
              &lt;HierarchicalDataTemplate ItemsSource="{Binding Children, Mode=TwoWay}"&gt;
                  &lt;controls:VisualElement DataContext="{Binding}"&gt;
                      &lt;Style TargetType="controls:ScrollDragZoomControl"&gt;
                          &lt;Style.Triggers&gt;
                              &lt;DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=controls:VisualElement}, Path=IsMouseHover}" Value="True"&gt;
                                  &lt;Setter Property="Active" Value="False" /&gt;
                              &lt;/DataTrigger&gt;
                              &lt;DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=controls:VisualElement}, Path=IsMouseHover}" Value="False"&gt;
                                  &lt;Setter Property="Active" Value="True" /&gt;
                              &lt;/DataTrigger&gt;
                          &lt;/Style.Triggers&gt;
                      &lt;/Style&gt;
                  &lt;/controls:VisualElement&gt;
              &lt;/HierarchicalDataTemplate&gt;
          &lt;/controls:OrgTreeView.ItemTemplate&gt;
      &lt;/controls:OrgTreeView&gt;
  &lt;/controls:ScrollDragZoomControl&gt;
  </code></pre>
  
  <p>With the solution above, the ScrollZoomDrag's DP "Active" doesn't get toggled at all. Am I missing something or is there a better approach?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p><strong>ScrollZoomDrag.xaml.cs</strong></p>
  
  <pre><code>        public static readonly DependencyProperty ActiveProperty = DependencyProperty.Register("Active", typeof(bool), typeof(ScrollDragZoomControl), new PropertyMetadata(true, new PropertyChangedCallback(ActiveChanged)));
  
      public bool Active
      {
          get { return (bool)GetValue(ActiveProperty); }
          set { SetValue(ActiveProperty, value); }
      }
  
      public static void ActiveChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
      {
          ScrollDragZoomControl scrollDragZoomControl = (ScrollDragZoomControl)obj;
  
          if ((bool)args.NewValue)
              scrollDragZoomControl.StartListen();
          else scrollDragZoomControl.StopListen();
      }
  </code></pre>
  
  <p><strong>VisualElement.xaml.cs</strong></p>
  
  <pre><code>        public static readonly DependencyProperty IsMouseHoverProperty = DependencyProperty.Register("IsMouseHover", typeof(bool), typeof(VisualElement), new PropertyMetadata(false));
  
      public VisualElement()
      {
          InitializeComponent();
          MouseEnter += VisualElement_MouseEnter;
          MouseLeave += VisualElement_MouseLeave;
      }
  
      public bool IsMouseHover
      {
          get { return (bool)GetValue(IsMouseHoverProperty); }
          set { SetValue(IsMouseHoverProperty, value); }
      }
  
      private void VisualElement_MouseLeave(object sender, MouseEventArgs e)
      {
          IsMouseHover = false;
      }
  
      private void VisualElement_MouseEnter(object sender, MouseEventArgs e)
      {
          IsMouseHover = true;
      }
  </code></pre>
  
  <p><strong>Approach 2: (Doesn't work either)</strong></p>
  
  <pre><code>    &lt;controls:ScrollDragZoomControl&gt;
      &lt;controls:ScrollDragZoomControl.Style&gt;
          &lt;Style TargetType="controls:ScrollDragZoomControl"&gt;
              &lt;Style.Triggers&gt;
                  &lt;DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=controls:VisualElement}, Path=IsMouseHover}" Value="True"&gt;
                      &lt;Setter Property="Active" Value="False" /&gt;
                  &lt;/DataTrigger&gt;
              &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
      &lt;/controls:ScrollDragZoomControl.Style&gt;
      &lt;controls:OrgTreeView ItemsSource="{Binding Root}"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"&gt;
          &lt;controls:OrgTreeView.ItemTemplate&gt;
              &lt;HierarchicalDataTemplate ItemsSource="{Binding Children, Mode=TwoWay}"&gt;
                  &lt;controls:VisualElement DataContext="{Binding}"&gt;                   
                  &lt;/controls:VisualElement&gt;
              &lt;/HierarchicalDataTemplate&gt;
          &lt;/controls:OrgTreeView.ItemTemplate&gt;
      &lt;/controls:OrgTreeView&gt;
  &lt;/controls:ScrollDragZoomControl&gt;
  </code></pre>