I have a TreeView that launches a new window when each of its TreeViewItems Selected events is fired.
<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Grid> <TreeView Name="treeView1"> <TreeViewItem Header="Root"> <TreeViewItem Header="Parent" Selected="ParentTreeViewItem_Selected"> <TreeViewItem Header="Child" Selected="TreeViewItem_Selected" ></TreeViewItem> </TreeViewItem> </TreeViewItem> </TreeView> </Grid> </Window>
Code for
namespace WpfApplication1
{Open partial class Window1: Window {public Window1 () {InitializeComponent (); }
private void TreeViewItem_Selected(object sender, RoutedEventArgs e) { Window w = new Window(); w.Show(); e.Handled = true; } private void ParentTreeViewItem_Selected(object sender, RoutedEventArgs e) { } }
}
When I click on a child of a node, a new window starts as expected. Be that as it may, after the words of his parents, the selected events launched the focus focus from a new window and marked the parent node as the current selection!
I expected that the new window would have focus, and the node that was clicked would turn gray, indicating a choice of users. Does anyone know why this is happening and how can I prevent it?
Thanks Brette
source share