I want to define a double click even on a TreeView so that I will be able to know which item in the TreeView was selected and to get his title. The way I try to get it's title gets me "MyProject.MenuItem". How can I refer to the selected item on the tree, make sure it's not the root, and get it's title? What I did:
<TreeView Name="trvMenu" HorizontalAlignment="Left" Height="312" VerticalAlignment="Top" Width="200" MouseDoubleClick="TreeView_MouseDoubleClick" >
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:MenuItem}" ItemsSource="{Binding Items}">
<TextBlock Text="{Binding Title}" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
The MessageBox shows "MyProject.MenuItem", what I want to do is not show a messagebox, but to get the title of the selected treeview item, after checking it is not the root
private void TreeView_MouseDoubleClick(object sender, RoutedEventArgs e)
{
if (sender is TreeViewItem)
if (!((TreeViewItem)sender).IsSelected)
return;
TreeViewItem tviSender = sender as TreeViewItem;
MessageBox.Show(trvMenu.SelectedItem.ToString());
}