void OnTreeViewItemSelected(object sender, RoutedEventArgs e) { RichEditTreeViewItem item = (RichEditTreeViewItem)sender; if (!item.IsSelected) { return; } CurrentTreeItem = item; richEdit.Document.ChangeActiveDocument(richEdit.Document); LayoutElement element = CurrentTreeItem.Info.Element; if (CurrentTreeItem.Info.DisplayAction == ContentDisplayAction.ScrollTo) { TryScrollToHeader(element); TryScrollToFooter(element); TryScrollToFloatingObject(element); TryScrollToComment(element); } else { RangedLayoutElement rangedElement = element as RangedLayoutElement; if (rangedElement == null) { return; } ScrollToPosition(rangedElement.Range.Start); richEdit.Document.Selection = richEdit.Document.CreateRange(rangedElement.Range.Start, rangedElement.Range.Length); } }
void AddTreeViewItem(ItemCollection collection, TreeViewItemInfo info) { RichEditTreeViewItem item = new RichEditTreeViewItem(info); item.Header = GetTreeViewItemHeader(info.Element, collection.Count + 1); item.Expanded += OnTreeViewItemExpanded; item.Selected += OnTreeViewItemSelected; collection.Add(item); }
void OnTreeViewItemExpanded(object sender, RoutedEventArgs e) { RichEditTreeViewItem item = (RichEditTreeViewItem)sender; if (item.HasItems) { return; } ChildElementsCollector collector = new ChildElementsCollector(item.Info); int itemsCount = collector.Collection.Count; for (int i = 0; i < itemsCount; i++) { AddTreeViewItem(item.Items, collector.Collection[i]); } }