protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) { base.OnPropertyChanged(e); if (e.Property == RowSelector.DataContextProperty) { Type rowType = null; Row row = this.DataContext as Row; if (row != null) { rowType = row.GetType(); } else { HeaderFooterItem hfi = this.DataContext as HeaderFooterItem; if (hfi != null) { row = hfi.AsVisual() as Row; if (row != null) { rowType = row.GetType(); } } } this.SetRowType(rowType); } }
private static bool IsContainerQualifying( FrameworkElement container, DataGridControl gridControl, double offset, double viewportSize, double opposedOffset, double opposedViewportSize, Orientation panelOrientation) { bool retval = true; HeaderFooterItem headerFooterItemContainer = container as HeaderFooterItem; Row rowContainer = container as Row; //Determine if the Element is Focusable or Navigable if (headerFooterItemContainer != null) { rowContainer = headerFooterItemContainer.AsVisual() as Row; if (rowContainer == null) { //If the HeaderFooter Item is not a Row and is Not focusable, then the item does not qualify. UIElement uiElementContainer = headerFooterItemContainer.AsVisual() as UIElement; if ((uiElementContainer == null) || (!uiElementContainer.Focusable)) { retval = false; } } } //If the container is a Row (in the headers footers region or not ) if ((retval) && (rowContainer != null)) { //and the Row is not navigable, then it does not qualify. if (rowContainer.NavigationBehavior == NavigationBehavior.None) { retval = false; } } //If the container still qualifies after first verification, check for the scrolling axis. if (retval) { //if the PrimaryAxis requires the opposed axis to be fully visible. if (((panelOrientation == Orientation.Vertical) && ((gridControl.ItemsPrimaryAxis == PrimaryAxis.Horizontal) || (gridControl.ItemsPrimaryAxis == PrimaryAxis.Both))) || ((panelOrientation == Orientation.Horizontal) && ((gridControl.ItemsPrimaryAxis == PrimaryAxis.Vertical) || (gridControl.ItemsPrimaryAxis == PrimaryAxis.Both)))) { FrameworkElement frameworkElementContainer = container as FrameworkElement; //Somehow, I decided that a container that is not a FrameworkElement (extremelly highly unprobable) was automaticaly NOT to qualify if opposed axis was required. if (frameworkElementContainer != null) { Vector rowOffset = VisualTreeHelper.GetOffset(frameworkElementContainer); double computedOffset = (panelOrientation == Orientation.Vertical) ? rowOffset.X : rowOffset.Y; double computedSize = (panelOrientation == Orientation.Vertical) ? frameworkElementContainer.ActualWidth : frameworkElementContainer.ActualHeight; //if the coordinates of the Row are NOT inside the Scrolling Axis' viewport... then the item is not qualifyable. if ((computedOffset < opposedOffset) || ((computedOffset + computedSize) > (opposedViewportSize + opposedOffset))) { retval = false; } } else { retval = false; } } } return(retval); }
private static void ProcessUnrealizedEndEdit( DataGridContext dataGridContext ) { Row row; object currentItemInEdition = dataGridContext.DataGridControl.m_currentItemInEdition; //first, determine if the item currently in edition is an Item or a [Group]Header/Footer if( dataGridContext.Items.Contains( currentItemInEdition ) ) { //the item currently in edition is a data item. DependencyObject container = dataGridContext.DataGridControl.CreateContainerForItem(); Debug.Assert( container != null, "CreateContainerForItem() returned null" ); row = container as Row; } else { DataTemplate template = DataGridControl.GetTemplateForItem( currentItemInEdition ); Debug.Assert( template != null, "DataTemplate for [Group]Header/Footer is null" ); HeaderFooterItem headerFooterItem = new HeaderFooterItem(); headerFooterItem.ContentTemplate = template; headerFooterItem.Measure( new Size( double.PositiveInfinity, double.PositiveInfinity ) ); row = headerFooterItem.AsVisual() as Row; } if( row != null ) { // Ensure to set the DataGridContext on the Container for the // PrepareItemContainer to correctly fetch the DataGridContext DataGridControl.SetDataGridContext( row, dataGridContext ); dataGridContext.DataGridControl.PrepareItemContainer( row, currentItemInEdition ); try { row.EndEdit(); } finally { dataGridContext.DataGridControl.ClearItemContainer( row, currentItemInEdition ); } } }