Hello:
I'm developing a TreeView
based control and my double click event continues to bubble up my TreeViewItem
nodes.
The goal is to have the TreeViewItem
expand or collapse when it is double clicked.
I have a style that applies an event handler for the MouseDoubleClick
event to each TreeViewItem
.
Here's the code that handles the event
private void TreeViewItemDoubleClicked( object sender, RoutedEventArgs e )
{
// Get the specific tree view item that was double clicked
TreeViewItem treeViewItem = sender as TreeViewItem;
// not null?
if( null != treeViewItem )
{
// Switch expanded state
if( true == treeViewItem.IsExpanded )
{
treeViewItem.IsExpanded = false;
}
else
{
treeViewItem.IsExpanded = true;
}
// Set event handled
e.Handled = true; // [1]
}
}
This works fine for the top level TreeViewItem
however when a child is double clicked, the event bubbles up the tree causing the entire branch to collapse. Why is the event continuing to bubble? As noted a [1]
I'm setting the event as handled.