Right now you have to double click or click the + icon. Is there any way to make it so if a user clicks anywhere on the node it expands?
+1
A:
Maybe is not the most elegant solution but this works:
static DependencyObject VisualUpwardSearch<T>(DependencyObject source)
{
while (source != null && source.GetType() != typeof(T))
source = VisualTreeHelper.GetParent(source);
return source;
}
then in the TreeViewItem.Selected Handler:
private void Treeview_Selected(object sender, RoutedEventArgs e)
{
var treeViewItem = VisualUpwardSearch<TreeViewItem>(e.OriginalSource as DependencyObject) as TreeViewItem;
if (treeViewItem != null) treeViewItem.IsExpanded = true;
}
the VisualUpwardSearch magic is taken from here: http://stackoverflow.com/questions/592373/select-treeview-node-on-right-click-before-displaying-contextmenu/594662#594662
Regards
Markust
2010-05-27 14:57:12