private void PrepareContainerWorker() { DependencyObject visualTree = this.AsVisual(); this.SetContainer(visualTree); // If the root of a HeaderFooterItem is not a IDataGridItemContainer, // drill down the VisualTree to ensure there are none var container = HeaderFooterItem.FindIDataGridItemContainerInChildren(this, visualTree, true); // Loop to prepare all IDataGridContainer found along the way. while (container != null) { // Row based objects apply their template though their implementation of PrepareContainer. // No need to call ApplyTemplate beforehand. if (!(container is Row)) { var frameworkElement = container as FrameworkElement; if (frameworkElement != null) { frameworkElement.ApplyTemplate(); } } container.PrepareContainer(m_initializingDataGridContext, m_initializingDataItem); container = HeaderFooterItem.FindIDataGridItemContainerInChildren(this, ( DependencyObject )container, false); } m_initializingDataGridContext = null; m_initializingDataItem = null; }
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); } }
internal static IDataGridItemContainer FindIDataGridItemContainerInChildren(HeaderFooterItem headerFooterItem, DependencyObject currentChild, bool checkRoot) { if (currentChild == null) { return(null); } IDataGridItemContainer container = currentChild as IDataGridItemContainer; if (checkRoot) { if (container != null) { return(container); } } int childCount = VisualTreeHelper.GetChildrenCount(currentChild); for (int i = 0; i < childCount; i++) { DependencyObject child = VisualTreeHelper.GetChild(currentChild, i); if (child == null) { continue; } if (!HeaderFooterItem.IsPartOfHeaderFooterItemTemplate(child, headerFooterItem)) { // We don't want to parse further the DataTemplate return(null); } container = child as IDataGridItemContainer; if (container != null) { return(container); } int innerChildCount = VisualTreeHelper.GetChildrenCount(child); if (innerChildCount > 0) { container = HeaderFooterItem.FindIDataGridItemContainerInChildren(headerFooterItem, child, false); } if (container != null) { return(container); } } return(null); }
protected internal void ClearContainer() { Visual visual = this.AsVisual(); // If the root of a HeaderFooterItem is not a IDataGridItemContainer, // drill down the VisualTree to ensure there are none var container = HeaderFooterItem.FindIDataGridItemContainerInChildren(this, visual); while (container != null) { container.ClearContainer(); container = HeaderFooterItem.FindIDataGridItemContainerInChildren(this, ( DependencyObject )container, false); } // Ensure we removed the HeaderFooterItem_Loaded event handler if // it was not yet loaded if (m_loadedHandler != null) { this.Loaded -= m_loadedHandler; m_loadedHandler = null; } }
private DependencyObject CreateHeaderFooterContainer( object dataItem ) { if( this.IsRecyclingEnabled ) { DependencyObject recycledContainer = null; recycledContainer = this.DequeueHeaderFooterContainer( dataItem ); if( recycledContainer != null ) return recycledContainer; } //If the container cannot be recycled, then create a new one. object realDataItem = dataItem; if( dataItem.GetType() == typeof( GroupHeaderFooterItem ) ) { realDataItem = ( ( GroupHeaderFooterItem )dataItem ).Template; } DataTemplate template = realDataItem as DataTemplate; if( template == null ) { GroupHeaderFooterItemTemplate vwc = realDataItem as GroupHeaderFooterItemTemplate; if( vwc != null ) { vwc.Seal(); template = vwc.Template; } if( template == null ) throw new DataGridInternalException(); } HeaderFooterItem newItem = new HeaderFooterItem(); BindingOperations.SetBinding( newItem, HeaderFooterItem.ContentProperty, m_headerFooterDataContextBinding ); newItem.ContentTemplate = template; return newItem; }
private static bool IsPartOfHeaderFooterItemTemplate(DependencyObject element, HeaderFooterItem headerFooterItem) { while (element != null) { DependencyObject templatedParent = null; var frameworkElement = element as FrameworkElement; if (frameworkElement != null) { templatedParent = frameworkElement.TemplatedParent; } else { var frameworkContentElement = element as FrameworkContentElement; if (frameworkContentElement != null) { templatedParent = frameworkContentElement.TemplatedParent; } } if (templatedParent == headerFooterItem) { return(true); } element = templatedParent; } return(false); }
internal static IDataGridItemContainer FindIDataGridItemContainerInChildren(HeaderFooterItem headerFooterItem, DependencyObject currentChild) { return(HeaderFooterItem.FindIDataGridItemContainerInChildren(headerFooterItem, currentChild, true)); }
private static bool IsPartOfHeaderFooterItemTemplate( DependencyObject element, HeaderFooterItem headerFooterItem ) { while( element != null ) { DependencyObject templatedParent = null; var frameworkElement = element as FrameworkElement; if( frameworkElement != null ) { templatedParent = frameworkElement.TemplatedParent; } else { var frameworkContentElement = element as FrameworkContentElement; if( frameworkContentElement != null ) { templatedParent = frameworkContentElement.TemplatedParent; } } if( templatedParent == headerFooterItem ) return true; element = templatedParent; } return false; }
internal static IDataGridItemContainer FindIDataGridItemContainerInChildren( HeaderFooterItem headerFooterItem, DependencyObject currentChild, bool checkRoot ) { if( currentChild == null ) return null; IDataGridItemContainer container = currentChild as IDataGridItemContainer; if( checkRoot ) { if( container != null ) return container; } int childCount = VisualTreeHelper.GetChildrenCount( currentChild ); for( int i = 0; i < childCount; i++ ) { DependencyObject child = VisualTreeHelper.GetChild( currentChild, i ); if( child == null ) continue; if( !HeaderFooterItem.IsPartOfHeaderFooterItemTemplate( child, headerFooterItem ) ) { // We don't want to parse further the DataTemplate return null; } container = child as IDataGridItemContainer; if( container != null ) return container; int innerChildCount = VisualTreeHelper.GetChildrenCount( child ); if( innerChildCount > 0 ) container = HeaderFooterItem.FindIDataGridItemContainerInChildren( headerFooterItem, child, false ); if( container != null ) return container; } return null; }
internal static IDataGridItemContainer FindIDataGridItemContainerInChildren( HeaderFooterItem headerFooterItem, DependencyObject currentChild ) { return HeaderFooterItem.FindIDataGridItemContainerInChildren( headerFooterItem, currentChild, true ); }
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 RefreshFixedHeaderFooter( DataGridControl dataGrid, Panel targetPanel, ObservableCollection<DataTemplate> collection ) { TableViewScrollViewer tableViewScrollViewer = dataGrid.ScrollViewer as TableViewScrollViewer; RowSelectorPane rowSelectorPane = ( tableViewScrollViewer != null ) ? tableViewScrollViewer.RowSelectorPane : null; foreach( HeaderFooterItem element in targetPanel.Children ) { if( rowSelectorPane != null ) { rowSelectorPane.FreeRowSelector( element ); } dataGrid.ClearItemContainer( element, GetFixedItem( element ) ); DataGridControl.SetDataGridContext( element, null ); } targetPanel.Children.Clear(); DataGridContext dataGridContext = dataGrid.DataGridContext; foreach( DataTemplate template in collection ) { HeaderFooterItem control = new HeaderFooterItem(); control.Content = dataGrid.DataContext; control.ContentTemplate = template; DataGridControl.SetDataGridContext( control, dataGridContext ); dataGrid.PrepareItemContainer( control, template ); DataGridControl.SetFixedItem( control, template ); GroupLevelIndicatorPane.SetGroupLevel( control, -1 ); targetPanel.Children.Add( control ); } }
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 ); } } }