I've been trying to get my WPF application to prompt users to either discard their unsaved changes or to cancel when they navigate using a TreeView.

I think I've found a bug. The MessageBox does not play nice with PreviewMouseDown. It seems to "handle" a click regardless of how its e.Handled is set if there's a MessageBox shown.

For this XAML...

<TreeView Name="TreeViewThings"
    ...
    PreviewMouseDown="TreeViewThings_PreviewMouseDown"
    TreeViewItem.Expanded="TreeViewThings_Expanded"
    TreeViewItem.Selected="TreeViewThings_Selected" >

...compare these alternative methods...

Sub TreeViewNodes_PreviewMouseDown(...)
    e.Handled = False
End Sub

Sub TreeViewNodes_PreviewMouseDown(...)
    MessageBox.Show("Test", "Test", MessageBoxButton.OK)
    e.Handled = False
End Sub

These two methods behave differently. Without the MessageBox, TreeViewNodes_Selected() or TreeViewThings_Expanded() will execute. With the MessageBox, they won't.

Is this a bug or is there something going on here that I should understand?

Edit
Report