Beispiel #1
0
        /// <summary>
        /// Let Renderer decide whether the parent grid should be allowed to handle keys and prevent
        /// the key event from being handled by the visual UIElement for this renderer. If this method
        /// returns true the parent grid will handle arrow keys and set the Handled flag in the event
        /// data. Keys that the grid does not handle will be ignored and be routed to the UIElement
        /// for this renderer.
        /// </summary>
        /// <param name="e">A <see cref="KeyEventArgs" /> object.</param>
        /// <returns>
        /// True if the parent grid should be allowed to handle keys; false otherwise.
        /// </returns>
        protected override bool ShouldGridTryToHandleKeyDown(KeyEventArgs e)
        {
            if (!HasCurrentCellState)
            {
                return(false);
            }
            var columnIndex = TreeGrid.ResolveToGridVisibleColumnIndex((this.CurrentCellElement as TreeGridCell).ColumnBase.ColumnIndex);
            var column      = ((TreeGridTemplateColumn)TreeGrid.Columns[columnIndex]);
            var handleTemplatedUIElementKeyDown = FocusManagerHelper.GetWantsKeyInput(column);


            if ((column.hasCellTemplate || column.hasCellTemplateSelector) && (column.hasEditTemplate || column.hasEditTemplateSelector))
            {
                handleTemplatedUIElementKeyDown = false;
            }
            switch (e.Key)
            {
            case Key.Space:
                return(!handleTemplatedUIElementKeyDown);

            case Key.A:
            case Key.V:
            case Key.X:
            case Key.C:
            {
                if (!handleTemplatedUIElementKeyDown && SelectionHelper.CheckControlKeyPressed() && !IsInEditing)
                {
                    return(true);
                }
                break;
            }

            case Key.F2:
            case Key.Escape:
            {
                e.Handled = true;
                return(true);
            }

            case Key.Tab:
                // When press tab continuously  and its reach to last one, then the focus goes to grid.Again if you press upo key, focus any of the content control. to avoid that the condition added.
                if (!IsInEditing && !(TreeGrid.GetLastDataRowIndex() == CurrentCellIndex.RowIndex && TreeGrid.SelectionController.CurrentCellManager.GetLastCellIndex() == CurrentCellIndex.ColumnIndex))
                {
                    // If Column with CellTemplate has editor loaded, then the click on that editor will not as we click or navigate to next cell, we need to remove the focus.
                    base.SetFocus(CurrentCellRendererElement, false);
                }
                return(true);

            case Key.Enter:
            case Key.PageUp:
            case Key.PageDown:
                if (!IsInEditing)
                {
                    // If Column with CellTemplate has editor loaded, then navigation of this key will set the focus.
                    base.SetFocus(CurrentCellRendererElement, true);
                }
                return(true);

            case Key.Home:
            case Key.End:
            case Key.Down:
            case Key.Up:
            case Key.Left:
            case Key.Right:
                // if Column has WantsKeyInput Enabled the navigation should be in editor.
            {
                if (!handleTemplatedUIElementKeyDown && !IsInEditing)
                {
                    base.SetFocus(CurrentCellRendererElement, false);
                    return(true);
                }
                else if (handleTemplatedUIElementKeyDown)
                {
                    return(false);
                }
                else
                {
                    return(!IsInEditing);
                }
            }

            case Key.Delete:
            {
                if (handleTemplatedUIElementKeyDown)
                {
                    return(false);
                }
                return(!IsInEditing);
            }
            }
            return(false);
        }