title: Delete from List in WPF C# with Commands
body: <p>I want you to be able to click on the delete button and then click on a targeted annotation on the screen and remove the selected annotation, however all that happens currently is that it deletes ALL annotations instead of even being able to select one. </p>
  
  <p>The button</p>
  
  <pre><code>&lt;StackPanel Orientation="Vertical" VerticalAlignment="Center"&gt;
                  &lt;customControls:ImageButton x:Name="BtnUndo" Height="30" Width="30" ImageSource="..\Images\undo.png" ToolTip="Undo" HorizontalAlignment="Center" VerticalAlignment="Top" Click="BtnUndo_Click" IsEnabled="False" Focusable="False"/&gt;
                  &lt;customControls:ImageButton x:Name="BtnRedo" Margin="0,2,0,2" Height="30" Width="30" ImageSource="..\Images\redo.png" ToolTip="Redo" HorizontalAlignment="Center" VerticalAlignment="Top" Click="BtnRedo_Click" IsEnabled="False" Focusable="False"/&gt;
                  &lt;customControls:ImageButton x:Name="BtnClear" Height="30" Width="30" ImageSource="..\Images\clear.png" ToolTip="Clear" HorizontalAlignment="Center" VerticalAlignment="Top" Click="BtnClear_Click" IsEnabled="False" Focusable="False"/&gt;
                  &lt;customControls:ImageButton x:Name="BtnDeleteTarget" Margin="60,-60,0,2" Height="30" Width="30" ImageSource="..\Images\clear.png" ToolTip="Clear" HorizontalAlignment="Center" VerticalAlignment="Top" Click="DeleteTarget_Click" IsEnabled="True" Focusable="False"/&gt;
              &lt;/StackPanel&gt;
  </code></pre>
  
  <p>The event</p>
  
  <pre><code>private void DeleteTarget_Click(object sender, RoutedEventArgs e)
  {
      Common.Commands.CommandManager.Get().Do(new ClearTargetAnnotation(_annotationManager));
  }
  </code></pre>
  
  <p>The Command</p>
  
  <pre><code>{
          private AnnotationManager _annotationManager;
          private List&lt;Annotation&gt; _annotations;
  
          public ClearTargetAnnotation(AnnotationManager annotationManager)
          {
              _annotationManager = annotationManager;
              _annotations = _annotationManager.GetAll();
          }
          public void Do()
          {
              foreach (var annotation in _annotations)
                  _annotationManager.Remove(annotation);
          }
  
          public void Undo()
          {
              _annotationManager.Set(_annotations);
          }
      }
  }
  </code></pre>
  
  <p>Remove method </p>
  
  <pre><code>public void Remove( Annotation annotation )
          {
              Monitor.Enter( _annotations );
              _annotations.Remove( annotation );
              Monitor.Exit( _annotations );
  
              annotation.OnMoved -= AnnotationMoved;
              Draw();
  
              if ( _annotations.Count == 0 )
                  IsEmptyChanged();
          }
  </code></pre>