protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (!e.Handled) { Key key = e.Key; switch (key) { case Key.Left: if (IsExpanded) { IsExpanded = false; } else { ParentTreeView.Selection.SelectParentFromKey(); } e.Handled = true; break; case Key.Right: if (CanExpand) { if (!IsExpanded) { IsExpanded = true; } else { ParentTreeView.Selection.SelectNextFromKey(); } } e.Handled = true; break; case Key.Up: ParentTreeView.Selection.SelectPreviousFromKey(); e.Handled = true; break; case Key.Down: ParentTreeView.Selection.SelectNextFromKey(); e.Handled = true; break; case Key.Home: ParentTreeView.Selection.SelectFirstFromKey(); e.Handled = true; break; case Key.End: ParentTreeView.Selection.SelectLastFromKey(); e.Handled = true; break; case Key.PageUp: ParentTreeView.Selection.SelectPageUpFromKey(); e.Handled = true; break; case Key.PageDown: ParentTreeView.Selection.SelectPageDownFromKey(); e.Handled = true; break; case Key.A: if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) { ParentTreeView.Selection.SelectAllFromKey(); e.Handled = true; } break; case Key.Add: if (CanExpandOnInput && !IsExpanded) { IsExpanded = true; } e.Handled = true; break; case Key.Multiply: if (CanExpandOnInput && !IsExpanded) { IsExpanded = true; ParentTreeView.RecursiveExpand(this); } e.Handled = true; break; case Key.Subtract: if (CanExpandOnInput && IsExpanded) { IsExpanded = false; } e.Handled = true; break; case Key.F2: if (ParentTreeView.AllowEditItems && ContentTemplateEdit != null && IsFocused && IsEditable) { IsEditing = true; e.Handled = true; } break; case Key.Escape: StopEditing(); e.Handled = true; break; case Key.Return: FocusHelper.Focus(this, true); IsEditing = false; e.Handled = true; break; case Key.Space: ParentTreeView.Selection.SelectCurrentBySpace(); e.Handled = true; break; } } }