title: How do I properly handle a PreviewMouseDown event with a MessageBox confirmation?
body: <p>Earlier I asked <a href="https://stackoverflow.com/questions/542392/how-can-i-cancel-a-users-wpf-treeview-click">how to cancel a WPF TreeViewItem.Selected event</a>.</p>
  
  <p>The answerers suggested I instead handle the PreviewMouseDown event before the selection even takes place.  That makes sense.</p>
  
  <p>I've tried to do that...</p>
  
  <p>XAML...</p>
  
  <pre><code>&lt;TreeView Name="TreeViewThings"
      ...
      PreviewMouseDown="TreeViewThings_PreviewMouseDown"
      TreeViewItem.Expanded="TreeViewThings_Expanded"
      TreeViewItem.Selected="TreeViewThings_Selected" &gt;
  </code></pre>
  
  <p>Visual Basic...</p>
  
  <pre>
  Sub TreeViewThings_PreviewMouseDown(...)
      If UnsavedChangesExist() Then
          e.Handled = UserCancelled()
      Else
          e.Handled = False
      End If
  End Sub
  
  Function UnsavedChangesExist() As Boolean
      ...
  End Function
  
  Function UserCancelled() As Boolean
      Return MessageBox.Show("Discard your unsaved changes?", _
                             "Unsaved Changes", _
                             MessageBoxButton.OKCancel, _
                             MessageBoxImage.Question) = MessageBoxResult.Cancel
  End Function
  </pre>
  
  <p>This is only sort of working...</p>
  
  <ul>
  <li>If there are no unsaved changes, then it proceeds just fine and executes TreeViewThings_Selected().</li>
  </ul>
  
  <p>If there are unsaved changes, then I see the MessageBox...</p>
  
  <p><a href="http://img25.imageshack.us/img25/141/discard2yk0.gif" rel="nofollow noreferrer">MessageBox: Continue and discard your unsaved changes?  OK/Cancel http://img25.imageshack.us/img25/141/discard2yk0.gif</a></p>
  
  <ul>
  <li><p>If I then choose Cancel, it cancels.</p></li>
  <li><p>However, If I instead choose OK to discard my unsaved changes, then it just cancels anyway--even though e.Handled = False.  It does not continue on and execute TreeViewThings_Selected().</p></li>
  </ul>
  
  <p>I think the fact that there's a MessageBox screws it up somehow.</p>
  
  <p>What am I doing wrong?</p>