public static ModernDataCell GetCurrentCell(this DataGridContext gridContext) { if (gridContext.CurrentItem == null || gridContext.CurrentColumn == null) { return(null); } if (gridContext.GetContainerFromItem(gridContext.CurrentItem) is not ModernDataRow row) { return(null); } return(row.Cells[gridContext.CurrentColumn] as ModernDataCell); }
public static bool FocusCurrent(this DataGridContext gridContext) { if (gridContext.CurrentItem != null && gridContext.CurrentColumn != null) { if (gridContext.GetContainerFromItem(gridContext.CurrentItem) is ModernDataRow row) { var cell = row.Cells[gridContext.CurrentColumn]; if (cell.IsFocused == false) { return(cell.Focus()); } } } return(false); }
protected virtual void HandlePreviewTabKey(KeyEventArgs e) { if (e.Handled) { return; } DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this); if (dataGridContext == null) { return; } DataGridContext currentDataGridContext = dataGridContext.DataGridControl.CurrentContext; if (currentDataGridContext == null) { return; } DependencyObject container = currentDataGridContext.GetContainerFromItem(currentDataGridContext.InternalCurrentItem); if (container != null) { KeyboardNavigationMode tabbingMode = KeyboardNavigation.GetTabNavigation(container); if (tabbingMode != KeyboardNavigationMode.None) { if ((Keyboard.Modifiers == ModifierKeys.None) || (Keyboard.Modifiers == ModifierKeys.Shift)) { DataGridItemsHost.BringIntoViewKeyboardFocusedElement(); //Force the "inline" relayout of the panel //This has no effect if the panel do not have to be updated. this.UpdateLayout(); } } } }
private static void MoveCenter(DataGridControl grid, object item, DataGridContext context) { grid.Dispatcher.BeginInvoke(new Action(delegate() { //moveUp(grid, context.GetContainerFromItem(item) as FrameworkElement); var cnt = context.GetContainerFromItem(item) as FrameworkElement; if (cnt == null) { return; } var point = cnt.TranslatePoint(new Point(0, 0), grid); var sv = grid.FindLogicalChild("PART_ScrollViewer") as ScrollViewer; if (sv == null) { return; } sv.ScrollToVerticalOffset(sv.VerticalOffset + (point.Y - 70) / sv.ViewportHeight); cnt.BringIntoView(); }), DispatcherPriority.ApplicationIdle); }
internal static void CancelEditHelper( DataGridContext dataGridContext ) { DataGridControl dataGridControl = dataGridContext.DataGridControl; if( !dataGridControl.IsBeingEdited ) return; if( !dataGridContext.IsCurrent ) throw new InvalidOperationException( "An attempt was made to call the CancelEdit method on a DataGridContext that is not current." ); DependencyObject container = dataGridContext.GetContainerFromItem( dataGridControl.m_currentItemInEdition ); //if the item is realized, then I could call the CancelEdit() directly on the container. if( container != null ) { Row row = Row.FromContainer( container ); if( row != null ) row.CancelEdit(); //not a row, then not editable. } //if the container is not realized, then I need to clear the parameters that indicate that the row is being edited. else { dataGridControl.UpdateCurrentRowInEditionCellStates( null, null ); } }
internal static void EndEditHelper( DataGridContext dataGridContext ) { DataGridControl dataGridControl = dataGridContext.DataGridControl; if( !dataGridControl.IsBeingEdited ) return; if( !dataGridContext.IsContainingItem( dataGridContext.DataGridControl.CurrentItemInEdition ) ) throw new InvalidOperationException( "An attempt was made to call the EndEdit method of an item that is not part of the specified context." ); DependencyObject container = dataGridContext.GetContainerFromItem( dataGridControl.m_currentItemInEdition ); //if the item is realized, then I could call the EndEdit() directly on the container. if( container != null ) { Row row = Row.FromContainer( container ); if( row != null ) row.EndEdit(); //not a row, then not editable. } //if the container is not realized, then I need to set things up so that when the container is realized, it's gonna resume edition. else { DataGridControl.ProcessUnrealizedEndEdit( dataGridContext ); } }
internal static void BeginEditHelper( DataGridContext dataGridContext, object item ) { DataGridControl dataGridControl = dataGridContext.DataGridControl; if( dataGridControl.IsBeingEdited ) return; if( item == null ) return; if( !dataGridContext.IsContainingItem( item ) ) throw new InvalidOperationException( "An attempt was made to call the BeginEdit method of an item that is not part of the specified context." ); DependencyObject container = dataGridContext.GetContainerFromItem( item ); //if the item is realized, then I could call the BeginEdit() directly on the container. if( container != null ) { Row row = Row.FromContainer( container ); if( row != null ) row.BeginEdit(); //not a row, then not editable. } //if the container is not realized, then I need to set things up so that when the container is realized, it's gonna resume edition. else { dataGridContext.DataGridControl.UpdateCurrentRowInEditionCellStates( null, item ); dataGridContext.DataGridControl.BringItemIntoView( item ); } }
internal bool BringItemIntoViewHelper( DataGridContext dataGridContext, object item ) { FrameworkElement itemsHost = this.ItemsHost; //this is a protection in case the Template is incomplete or not realized yet. if( itemsHost == null ) return false; // It is possible that a BringIntoView was queued before an operation that will // detach the ItemsHost of the DataGridControl and we want to avoid to call // ICustomVirtualizingPanel.BringIntoView in this situation. DataGridContext itemsHostDataGridContext = DataGridControl.GetDataGridContext( itemsHost ); if( itemsHostDataGridContext == null ) { return false; } FrameworkElement container = dataGridContext.GetContainerFromItem( item ) as FrameworkElement; //if a container exists, call bring into view on it! if( container != null ) { container.BringIntoView(); //flag the function as being successful return true; } // The container does not exist, it is not yet realized. // If we are not virtualizing any items, return. // The call to SetFocusHelper when the BringIntoView completes will call a FrameworkElement BringIntoView // which will cause the ScrollViewer to bring the item into view approprietly. if( ( this.ScrollViewer != null ) && ( !this.ScrollViewer.CanContentScroll ) ) return false; ICustomVirtualizingPanel customPanel = itemsHost as ICustomVirtualizingPanel; if( customPanel == null ) return false; int index = this.GetGlobalGeneratorIndexFromItem( null, item ); if( index != -1 ) { //call the special function to bring an index into view. customPanel.BringIntoView( index ); return true; } return false; }