title: Best way to prevent unselect last selected item in ListBox
body: <p>I need to implement custom behavior for ListBox control in wpf.
  The idea is to disable unselect last selected element. According to default behavior when user clicks on selected item with mouse, holding ctrl key pressed, the selection disappears. I need to implement some logic to make listbox do nothing when user click mouse+ctrl on last selected item. </p>
  
  <p>The only approach i have found is to subscribe to ListBox.SelectionChanged and do something like this:</p>
  
  <pre><code>private static void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
          {
              var listBox = sender as ListBox;
              if (listBox != null &amp;&amp; e.RemovedItems != null &amp;&amp; e.RemovedItems.Count == 1)
              {
                  var removed = e.RemovedItems[0];
                  if (listBox.SelectedItems.Count == 0)
                  {
                      if (listBox.SelectionMode == System.Windows.Controls.SelectionMode.Single)
                      {
                          listBox.SelectedItem = removed;
                      }
                      else
                      {
                          listBox.SelectedItems.Add(removed);
                      }
  
                      e.Handled = true;
                  }
              }
          }
  </code></pre>
  
  <p>but this solution is not suitable for me, because in this case some undesired calls happens when ListBox.SelectedItem is bound to viewmodel property.</p>
  
  <p>pseudo callstack (when unselecting selected item):</p>
  
  <ol>
  <li><p>SelectedItem changed to null</p></li>
  <li><p>listBox_SelectionChanged is called</p></li>
  <li><p>SelectedItem is set to previous value</p></li>
  </ol>
  
  <p>All i want is that steps 1 and 3 don`t ever happen. It is important because when SelectedItem changes some long-running async operation is started.</p>
  
  <p>Thank you, any advices would be appreciated!</p>