public void SelectNode(int lineNumber) { try { var n = FileStructureControl.FindNode(this.treeview.ItemsSource as IEnumerable <Node>, lineNumber); if (n != null) { n.IsSelected = true; } var c = this.treeview.ItemContainerGenerator.ContainerFromItem(n); } catch { } }
static Node FindNode(IEnumerable <Node> nodes, int line) { Node bestnode = null; foreach (var n in nodes) { var r = n.Astnode.Range; if (r.StartLine <= line) { bestnode = n; } else { break; } } if (bestnode == null) { return(null); } //Trace.WriteLine($"match node {bestnode.Astnode.Range}"); return(FileStructureControl.FindNode(bestnode.Children, line) ?? bestnode); }