Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF: Does MessageBox Break PreviewMouseDown?
    primarykey
    data
    text
    <p>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.</p> <ul> <li><a href="https://stackoverflow.com/questions/542392/how-can-i-cancel-a-users-wpf-treeview-click">How can I cancel a user’s WPF TreeView click?</a></li> <li><a href="https://stackoverflow.com/questions/543312/how-do-i-properly-handle-a-previewmousedown-event-with-a-messagebox-confirmation/545534#545534">How do I properly handle a PreviewMouseDown event with a MessageBox confirmation?</a></li> </ul> <p>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.</p> <p>For this XAML...</p> <pre><code>&lt;TreeView Name="TreeViewThings" ... PreviewMouseDown="TreeViewThings_PreviewMouseDown" TreeViewItem.Expanded="TreeViewThings_Expanded" TreeViewItem.Selected="TreeViewThings_Selected" &gt; </code></pre> <p>...compare these alternative methods...</p> <pre> Sub TreeViewNodes_PreviewMouseDown(...) e.Handled = False End Sub Sub TreeViewNodes_PreviewMouseDown(...) MessageBox.Show("Test", "Test", MessageBoxButton.OK) e.Handled = False End Sub </pre> <p>These two methods behave differently. Without the MessageBox, <code>TreeViewNodes_Selected()</code> or <code>TreeViewThings_Expanded()</code> will execute. With the MessageBox, they won't.</p> <p>Is this a bug or is there something going on here that I should understand?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload