title: How to bind dependency property of ICommand of ItemsControl member to parent view model?
body: <p>I have a custom user control that has a checkbox and a button with backing dependency properties.</p>
  <p>I also have a window with an ItemsControl and I bind that control's &quot;ItemsSource&quot; to an ObservableCollection containing said user controls.</p>
  <p>My goal is to be able to access the dependency properties in the window's view model, so I can check whether the checkbox of each member of the collection is checked or not and when the user clicks the button - remove the user control containing the button from the collection.</p>
  <h3>This is my code</h3>
  <p>User control XAML:</p>
  <pre><code>&lt;CheckBox IsChecked=&quot;{Binding cbChecked,
              Mode=OneWayToSource,
              UpdateSourceTrigger=PropertyChanged,
              RelativeSource={RelativeSource FindAncestor,
              AncestorType=UserControl}}&quot;/&gt;
  
  
  &lt;Button Content=&quot;X&quot;
          Command=&quot;{Binding RemoveCommand,
                      RelativeSource={RelativeSource FindAncestor,
                      AncestorType=UserControl}}&quot;&gt;
  </code></pre>
  <p>(note I am not sure if I need the &quot;UpdateSourceTrigger&quot;)</p>
  <p>User control codebehind:</p>
  <pre><code>    public ICommand RemoveCommand
      {
          get { return (ICommand)GetValue(RemoveCommandProperty); }
          set { SetValue(RemoveCommandProperty, value); }
      }
  
      // Using a DependencyProperty as the backing store for RemoveCommand.  This enables animation, styling, binding, etc...
      public static readonly DependencyProperty RemoveCommandProperty =
          DependencyProperty.Register(&quot;RemoveCommand&quot;, typeof(ICommand), typeof(CustomUserControl), new PropertyMetadata(OnAnyPropertyChanged));
  
      public bool cbChecked
      {
          get { return (bool)GetValue(cbCheckedProperty); }
          set { SetValue(cbCheckedProperty, value); }
      }
  
      // Using a DependencyProperty as the backing store for cbChecked.  This enables animation, styling, binding, etc...
      public static readonly DependencyProperty cbCheckedProperty =
          DependencyProperty.Register(&quot;cbChecked&quot;, typeof(bool), typeof(CustomUserControl), new PropertyMetadata(OnAnyPropertyChanged));
  
      static void OnAnyPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
          =&gt; (obj as CustomUserControl).OnAnyPropertyChanged(args);
  
      void OnAnyPropertyChanged(DependencyPropertyChangedEventArgs args)
          =&gt; AnyPropertyChanged?.Invoke(this, args);
  </code></pre>
  <p>Window XAML:</p>
  <pre><code>        &lt;ScrollViewer VerticalScrollBarVisibility=&quot;Visible&quot; Grid.Row=&quot;0&quot;&gt;
              &lt;ItemsControl ItemsSource=&quot;{Binding ControlsCollection}&quot; HorizontalAlignment=&quot;Stretch&quot; VerticalAlignment=&quot;Top&quot;&gt;
                  &lt;ItemsControl.ItemContainerStyle&gt;
                      &lt;Style&gt;
                          &lt;Setter Property=&quot;FrameworkElement.Margin&quot; Value=&quot;5,20,0,0&quot;/&gt;
                      &lt;/Style&gt;
                  &lt;/ItemsControl.ItemContainerStyle&gt;
              &lt;/ItemsControl&gt;
          &lt;/ScrollViewer&gt;
  </code></pre>
  <h2>How can I make it so when the user clicks the &quot;X&quot; button the user control that holds it is removed from the collection AND be able to check the checkbox &quot;checked&quot; status from the window's view model?</h2>