public static SharpTreeViewTextSearch GetInstance(SharpTreeView sharpTreeView) { var textSearch = (SharpTreeViewTextSearch)sharpTreeView.GetValue(TextSearchInstanceProperty); if (textSearch == null) { textSearch = new SharpTreeViewTextSearch(sharpTreeView); sharpTreeView.SetValue(TextSearchInstanceProperty, textSearch); } return(textSearch); }
protected override void OnTextInput(TextInputEventArgs e) { if (!string.IsNullOrEmpty(e.Text) && IsTextSearchEnabled && (e.Source == this || ItemContainerGenerator.IndexFromContainer(e.Source as IControl) != -1)) { var instance = SharpTreeViewTextSearch.GetInstance(this); if (instance != null) { instance.Search(e.Text); e.Handled = true; } } if (!e.Handled) { base.OnTextInput(e); } }
protected override void OnKeyDown(KeyEventArgs e) { SharpTreeViewItem container = e.Source as SharpTreeViewItem; switch (e.Key) { case Key.Left: if (container != null && ItemContainerGenerator.IndexFromContainer(e.Source as IControl) != -1) { if (container.Node.IsExpanded) { container.Node.IsExpanded = false; } else if (container.Node.Parent != null) { this.FocusNode(container.Node.Parent); } e.Handled = true; } break; case Key.Right: // TODO: focus on first child if (container != null && ItemContainerGenerator.IndexFromContainer(e.Source as IControl) != -1) { if (!container.Node.IsExpanded && container.Node.ShowExpander) { container.Node.IsExpanded = true; } else if (container.Node.Children.Count > 0) { // jump to first child: //container.MoveFocus(new TraversalRequest(FocusNavigationDirection.Down)); } e.Handled = true; } break; case Key.Return: case Key.Space: if (container != null && e.Modifiers == InputModifiers.None && this.SelectedItems.Count == 1 && this.SelectedItem == container.Node) { container.Node.ActivateItem(e); } break; case Key.Add: if (container != null && ItemContainerGenerator.IndexFromContainer(e.Source as IControl) != -1) { container.Node.IsExpanded = true; e.Handled = true; } break; case Key.Subtract: if (container != null && ItemContainerGenerator.IndexFromContainer(e.Source as IControl) != -1) { container.Node.IsExpanded = false; e.Handled = true; } break; case Key.Multiply: if (container != null && ItemContainerGenerator.IndexFromContainer(e.Source as IControl) != -1) { container.Node.IsExpanded = true; ExpandRecursively(container.Node); e.Handled = true; } break; case Key.Back: if (IsTextSearchEnabled) { var instance = SharpTreeViewTextSearch.GetInstance(this); if (instance != null) { instance.RevertLastCharacter(); e.Handled = true; } } break; } if (!e.Handled) { base.OnKeyDown(e); } }