protected virtual void HandlePageEndKey(KeyEventArgs e) { if (e.Handled) { return; } DataGridContext dataGridContext = null; if (e.OriginalSource != null) { dataGridContext = DataGridControl.GetDataGridContext(e.OriginalSource as DependencyObject); } else { dataGridContext = DataGridControl.GetDataGridContext(this); } if (dataGridContext == null) { return; } PagingBehavior pagingBehavior = dataGridContext.DataGridControl.PagingBehavior; NavigationBehavior navigationBehavior = dataGridContext.DataGridControl.NavigationBehavior; ColumnBase CurrentColumn = dataGridContext.CurrentColumn; if (((navigationBehavior == NavigationBehavior.CellOnly) || (navigationBehavior == NavigationBehavior.RowOrCell)) && (CurrentColumn != null)) { int oldCurrentIndex = CurrentColumn.Index; NavigationHelper.MoveFocusToLastVisibleColumn(dataGridContext); //if the last focusable column is is within the viewport, scroll to Extended offset, otherwise, bringIntoView if ((this.IsCellsOffsetNeedReset(dataGridContext)) && (oldCurrentIndex == CurrentColumn.Index)) { this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(this.ScrollToRightEnd)); } if ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { if (pagingBehavior == PagingBehavior.TopToBottom) { this.ScrollToBottom(); } else { this.ScrollToRightEnd(); } this.HandlePageDownNavigation(); } } else { if ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { this.ScrollToBottom(); this.ScrollToRightEnd(); // Than handle new selection! if (navigationBehavior != NavigationBehavior.None) { this.HandlePageDownNavigation(); } } else { if (pagingBehavior == PagingBehavior.TopToBottom) { this.ScrollToRightEnd(); } else { this.ScrollToBottom(); } } } e.Handled = true; }
protected virtual void HandlePageDownKey(KeyEventArgs e) { if (e.Handled) { return; } DataGridContext dataGridContext = null; if (e.OriginalSource != null) { dataGridContext = DataGridControl.GetDataGridContext(e.OriginalSource as DependencyObject); } else { dataGridContext = DataGridControl.GetDataGridContext(this); } if (dataGridContext == null) { return; } DataGridControl dataGridControl = dataGridContext.DataGridControl; PagingBehavior pagingBehavior = dataGridControl.PagingBehavior; NavigationBehavior navigationBehavior = dataGridControl.NavigationBehavior; // If the Ctrl Modifier was held at the same time if ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { // Scroll to absolute end of the scroll viewer if (pagingBehavior == PagingBehavior.TopToBottom) { this.ScrollToBottom(); } else { this.ScrollToRightEnd(); } // Then handle new selection! if (navigationBehavior != NavigationBehavior.None) { this.HandlePageDownNavigation(); } } //No special modifiers were held else { FrameworkElement lastVisibleContainer = ScrollViewerHelper.GetLastVisibleContainer( dataGridControl, dataGridControl.ItemsHost, this); if (lastVisibleContainer != null) { // There is an identified weakness with the IsKeyboardFocusWithin property where // it cannot tell if the focus is within a Popup which is within the element // This has been identified, and only the places where it caused problems // were fixed... This comment is only here to remind developpers of the flaw // If the item has keyboard focus if ((lastVisibleContainer.IsKeyboardFocusWithin) || (lastVisibleContainer.IsKeyboardFocused) || (navigationBehavior == NavigationBehavior.None)) { // Then scroll if (pagingBehavior == PagingBehavior.TopToBottom) { this.PageDown(); } else { this.PageRight(); } } //and process new selection if (navigationBehavior != NavigationBehavior.None) { this.HandlePageDownNavigation(); } } else { // Normaly for when we are in dataGridControl.NavigationBehavior == NavigationBehavior.None if (pagingBehavior == PagingBehavior.TopToBottom) { this.PageDown(); } else { this.PageRight(); } } } e.Handled = true; }
protected virtual void HandlePageHomeKey(KeyEventArgs e) { if (e.Handled) { return; } DataGridContext dataGridContext = null; if (e.OriginalSource != null) { dataGridContext = DataGridControl.GetDataGridContext(e.OriginalSource as DependencyObject); } else { dataGridContext = DataGridControl.GetDataGridContext(this); } if (dataGridContext == null) { return; } PagingBehavior pagingBehavior = dataGridContext.DataGridControl.PagingBehavior; NavigationBehavior navigationBehavior = dataGridContext.DataGridControl.NavigationBehavior; ColumnBase currentColumn = dataGridContext.CurrentColumn; if (((navigationBehavior == NavigationBehavior.CellOnly) || (navigationBehavior == NavigationBehavior.RowOrCell)) && (currentColumn != null)) { int oldCurrentIndex = currentColumn.Index; NavigationHelper.MoveFocusToFirstVisibleColumn(dataGridContext); var columnVirtualizationManager = dataGridContext.ColumnVirtualizationManager as TableViewColumnVirtualizationManagerBase; //if the first focusable column is is within the viewport, scroll so 0d offset, otherwise, bringIntoView bool isFixedColumn = (columnVirtualizationManager == null) ? false : columnVirtualizationManager.GetFixedFieldNames().Contains(currentColumn.FieldName); if (((this.IsCellsOffsetNeedReset(dataGridContext)) && (oldCurrentIndex == currentColumn.Index)) || (isFixedColumn)) { this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(this.ScrollToLeftEnd)); } if ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { if (pagingBehavior == PagingBehavior.TopToBottom) { this.ScrollToTop(); } else { this.ScrollToLeftEnd(); } this.HandlePageUpNavigation(); } } else { if ((e.KeyboardDevice.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { this.ScrollToTop(); this.ScrollToLeftEnd(); //than handle new selection! if (navigationBehavior != NavigationBehavior.None) { this.HandlePageUpNavigation(); } } else { if (pagingBehavior == PagingBehavior.TopToBottom) { this.ScrollToLeftEnd(); } else { this.ScrollToTop(); } } } e.Handled = true; }
protected virtual void HandleSystemKey(KeyEventArgs e) { if (e.Handled) { return; } DataGridContext dataGridContext = null; if (e.OriginalSource != null) { dataGridContext = DataGridControl.GetDataGridContext(e.OriginalSource as DependencyObject); } else { dataGridContext = DataGridControl.GetDataGridContext(this); } if (dataGridContext == null) { return; } PagingBehavior pagingBehavior = dataGridContext.DataGridControl.PagingBehavior; // If Alt-PageDown was pressed if (e.SystemKey == Key.PageDown) { // Process Paging in opposed axis if (pagingBehavior == PagingBehavior.TopToBottom) { this.PageRight(); } else { this.PageDown(); } e.Handled = true; } // If Alt-PageUp was pressed else if (e.SystemKey == Key.PageUp) { // Process scrolling in opposed axis if (pagingBehavior == PagingBehavior.TopToBottom) { this.PageLeft(); } else { this.PageUp(); } e.Handled = true; } else { // If neither Alt-PageUp or alt-PageDown, flag the input as non-processed. e.Handled = false; } }