Exemplo n.º 1
0
        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;
                    }

                    e.Handled = true;
                    break;

                case Key.Right:
                    IsExpanded = true;
                    e.Handled  = true;
                    break;

                case Key.Up:
                    ParentTreeView.SelectPreviousFromKey();
                    e.Handled = true;
                    break;

                case Key.Down:
                    ParentTreeView.SelectNextFromKey();
                    e.Handled = true;
                    break;

                case Key.Add:
                    if (IsExpandableOnInput && !IsExpanded)
                    {
                        IsExpanded = true;
                    }

                    e.Handled = true;
                    break;

                case Key.Subtract:
                    if (IsExpandableOnInput && IsExpanded)
                    {
                        IsExpanded = false;
                    }

                    e.Handled = true;
                    break;

                case Key.F2:
                    e.Handled = StartEditing();
                    break;

                case Key.Escape:
                case Key.Return:
                    StopEditing();
                    e.Handled = true;
                    break;

                case Key.Space:
                    ParentTreeView.SelectCurrentBySpace();
                    e.Handled = true;
                    break;

                case Key.Home:
                    ParentTreeView.SelectFirst();
                    e.Handled = true;
                    break;

                case Key.End:
                    ParentTreeView.SelectLast();
                    e.Handled = true;
                    break;
                }
            }
        }
Exemplo n.º 2
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            if (e.Handled)
            {
                return;
            }

            switch (e.Key)
            {
            case Key.Add:
                if (CanExpandOnInput && !IsExpanded)
                {
                    SetCurrentValue(IsExpandedProperty, true);
                    e.Handled = true;
                }
                break;

            case Key.Subtract:
                if (CanExpandOnInput && IsExpanded)
                {
                    SetCurrentValue(IsExpandedProperty, false);
                    e.Handled = true;
                }
                break;

            case Key.Left:
            case Key.Right:
                if (LogicalLeft(e.Key))
                {
                    if (CanExpandOnInput && IsExpanded)
                    {
                        if (IsFocused)
                        {
                            SetCurrentValue(IsExpandedProperty, false);
                        }
                        else
                        {
                            Focus();
                        }
                    }
                    else
                    {
                        ParentTreeView.SelectParentFromKey();
                    }
                }
                else
                {
                    if (CanExpandOnInput)
                    {
                        if (!IsExpanded)
                        {
                            SetCurrentValue(IsExpandedProperty, true);
                        }
                        else
                        {
                            ParentTreeView.SelectNextFromKey();
                        }
                    }
                }
                e.Handled = true;
                break;

            case Key.Down:
                ParentTreeView.SelectNextFromKey();
                e.Handled = true;
                break;

            case Key.Up:
                ParentTreeView.SelectPreviousFromKey();
                e.Handled = true;
                break;

            case Key.F2:
                e.Handled = StartEditing();
                break;

            case Key.Escape:
            case Key.Return:
                StopEditing();
                e.Handled = true;
                break;

            case Key.Space:
                ParentTreeView.SelectCurrentBySpace();
                e.Handled = true;
                break;

            case Key.Home:
                ParentTreeView.SelectFirst();
                e.Handled = true;
                break;

            case Key.End:
                ParentTreeView.SelectLast();
                e.Handled = true;
                break;
            }
        }