示例#1
0
        internal void ClearItemContainer(object item, ItemsControl parentItemsControl)
        {
            if (VirtualizingPanel.GetIsVirtualizing(parentItemsControl))
            {
                //
                // ItemValueStorage:  save off values for this container if we're a virtualizing TreeView.
                //

                //
                // Right now we have a hard-coded list of DPs we want to save off.  In the future we could provide a 'register' API
                // so that each ItemsControl could decide what DPs to save on its containers. Maybe we define a virtual method to
                // retrieve a list of DPs the type is interested in.  Alternatively we could have the contract
                // be that ItemsControls use the ItemStorageService inside their ClearContainerForItemOverride by calling into StoreItemValues.
                //
                Helper.StoreItemValues(parentItemsControl, this, item);

                // Tell the panel to clear off all its containers.  This will cause this method to be called
                // recursively down the tree, allowing all descendent data to be stored before we save off
                // the ItemValueStorage DP for this container.

                VirtualizingPanel vp = ItemsHost as VirtualizingPanel;
                if (vp != null)
                {
                    vp.OnClearChildrenInternal();
                }

                ItemContainerGenerator.RemoveAllInternal(true /*saveRecycleQueue*/);
            }

            // this container is going away - forget about its selection
            ContainsSelection = false;
        }
        // Token: 0x06005A24 RID: 23076 RVA: 0x0018D68C File Offset: 0x0018B88C
        internal static void OnVirtualizationPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ItemsControl itemsControl = d as ItemsControl;

            if (itemsControl != null)
            {
                Panel itemsHost = itemsControl.ItemsHost;
                if (itemsHost != null)
                {
                    itemsHost.InvalidateMeasure();
                    ItemsPresenter itemsPresenter = VisualTreeHelper.GetParent(itemsHost) as ItemsPresenter;
                    if (itemsPresenter != null)
                    {
                        itemsPresenter.InvalidateMeasure();
                    }
                    if (d is TreeView)
                    {
                        DependencyProperty property = e.Property;
                        if (property == VirtualizingStackPanel.IsVirtualizingProperty || property == VirtualizingPanel.IsVirtualizingWhenGroupingProperty || property == VirtualizingStackPanel.VirtualizationModeProperty || property == VirtualizingPanel.ScrollUnitProperty)
                        {
                            VirtualizingPanel.VirtualizationPropertyChangePropagationRecursive(itemsControl, itemsHost);
                        }
                    }
                }
            }
        }
示例#3
0
		// Token: 0x06004E0F RID: 19983 RVA: 0x0015FE30 File Offset: 0x0015E030
		internal void ClearItemContainer(object item, ItemsControl parentItemsControl)
		{
			if (this.Generator == null)
			{
				return;
			}
			if (parentItemsControl != null && VirtualizingPanel.GetIsVirtualizingWhenGrouping(parentItemsControl))
			{
				Helper.StoreItemValues(parentItemsControl, this, item);
				if (this._expander != null)
				{
					Helper.StoreItemValues(parentItemsControl, this._expander, item);
				}
				VirtualizingPanel virtualizingPanel = this._itemsHost as VirtualizingPanel;
				if (virtualizingPanel != null)
				{
					virtualizingPanel.OnClearChildrenInternal();
				}
				this.Generator.RemoveAllInternal(true);
			}
			else
			{
				this.Generator.Release();
			}
			base.ClearContentControl(item);
		}
示例#4
0
        /// <summary>
        /// Recursively & syncronously expand all the nodes in this subtree.
        /// </summary>
        private static void ExpandRecursive(TreeViewItem item)
        {
            if (item == null)
            {
                return;
            }

            // Expand the current item
            if (!item.IsExpanded)
            {
                item.SetCurrentValueInternal(IsExpandedProperty, BooleanBoxes.TrueBox);
            }

            // ApplyTemplate in order to generate the ItemsPresenter and the ItemsPanel. Note that in the
            // virtualizing case even if the item is marked expanded we still need to do this step in order to
            // regenerate the visuals because they may have been virtualized away.

            item.ApplyTemplate();
            ItemsPresenter itemsPresenter = (ItemsPresenter)item.Template.FindName(ItemsHostPartName, item);

            if (itemsPresenter != null)
            {
                itemsPresenter.ApplyTemplate();
            }
            else
            {
                item.UpdateLayout();
            }

            VirtualizingPanel virtualizingPanel = item.ItemsHost as VirtualizingPanel;

            item.ItemsHost.EnsureGenerator();

            for (int i = 0, count = item.Items.Count; i < count; i++)
            {
                TreeViewItem subitem;
                if (virtualizingPanel != null)
                {
                    // We need to bring the item into view so that the container will be generated.
                    virtualizingPanel.BringIndexIntoView(i);

                    subitem = (TreeViewItem)item.ItemContainerGenerator.ContainerFromIndex(i);
                }
                else
                {
                    subitem = (TreeViewItem)item.ItemContainerGenerator.ContainerFromIndex(i);

                    // We dont actually need to bring this into view, but we'll do it
                    // anyways to maintain the same behavior as with a virtualizing panel.
                    subitem.BringIntoView();
                }

                if (subitem != null)
                {
                    ExpandRecursive(subitem);
                }
            }
        }
 // Token: 0x0600592F RID: 22831 RVA: 0x0018A4C1 File Offset: 0x001886C1
 internal void PrepareItemContainer(object item, ItemsControl parentItemsControl)
 {
     Helper.ClearVirtualizingElement(this);
     TreeViewItem.IsVirtualizingPropagationHelper(parentItemsControl, this);
     if (VirtualizingPanel.GetIsVirtualizing(parentItemsControl))
     {
         Helper.SetItemValuesOnContainer(parentItemsControl, this, item);
     }
 }
示例#6
0
        //------------------------------------------------------
        //
        // Private Methods
        //
        //------------------------------------------------------

        // initialize (called during measure, from ApplyTemplate)
        void AttachToOwner()
        {
            DependencyObject       templatedParent = this.TemplatedParent;
            ItemsControl           owner           = templatedParent as ItemsControl;
            ItemContainerGenerator generator;

            if (owner != null)
            {
                // top-level presenter - get information from ItemsControl
                generator = owner.ItemContainerGenerator;
            }
            else
            {
                // subgroup presenter - get information from GroupItem
                GroupItem      parentGI = templatedParent as GroupItem;
                ItemsPresenter parentIP = FromGroupItem(parentGI);

                if (parentIP != null)
                {
                    owner = parentIP.Owner;
                }

                generator = (parentGI != null) ? parentGI.Generator : null;
            }

            _owner = owner;
            UseGenerator(generator);

            // create the panel, based either on ItemsControl.ItemsPanel or GroupStyle.Panel
            ItemsPanelTemplate template   = null;
            GroupStyle         groupStyle = (_generator != null) ? _generator.GroupStyle : null;

            if (groupStyle != null)
            {
                // If GroupStyle.Panel is set then we dont honor ItemsControl.IsVirtualizing
                template = groupStyle.Panel;
                if (template == null)
                {
                    // create default Panels
                    if (VirtualizingPanel.GetIsVirtualizingWhenGrouping(owner))
                    {
                        template = GroupStyle.DefaultVirtualizingStackPanel;
                    }
                    else
                    {
                        template = GroupStyle.DefaultStackPanel;
                    }
                }
            }
            else
            {
                // Its a leaf-level ItemsPresenter, therefore pick ItemsControl.ItemsPanel
                template = (_owner != null) ? _owner.ItemsPanel : null;
            }
            Template = template;
        }
示例#7
0
        internal void ClearItemContainer(object item, ItemsControl parentItemsControl)
        {
            if (Generator == null)
            {
                return;     // user-declared GroupItem - ignore (bug 108423)
            }
            ItemContainerGenerator generator  = Generator.Parent;
            GroupStyle             groupStyle = generator.GroupStyle;

            if (Object.Equals(this.Content, item))
            {
                ClearValue(ContentProperty);
            }
            if (this.ContentTemplate == groupStyle.HeaderTemplate)
            {
                ClearValue(ContentTemplateProperty);
            }
            if (this.ContentTemplateSelector == groupStyle.HeaderTemplateSelector)
            {
                ClearValue(ContentTemplateSelectorProperty);
            }
            if (this.ContentStringFormat == groupStyle.HeaderStringFormat)
            {
                ClearValue(ContentStringFormatProperty);
            }

            //
            // ItemValueStorage:  save off values for this container if we're a virtualizing Group.
            //
            if (parentItemsControl != null && VirtualizingPanel.GetIsVirtualizingWhenGrouping(parentItemsControl))
            {
                Helper.StoreItemValues((IContainItemStorage)parentItemsControl, this, item);

                if (_expander != null)
                {
                    Helper.StoreItemValues((IContainItemStorage)parentItemsControl, _expander, item);
                }

                // Tell the panel to clear off all its containers.  This will cause this method to be called
                // recursively down the tree, allowing all descendent data to be stored before we save off
                // the ItemValueStorage DP for this container.

                VirtualizingPanel vp = _itemsHost as VirtualizingPanel;
                if (vp != null)
                {
                    vp.OnClearChildrenInternal();
                }

                Generator.RemoveAllInternal(true /*saveRecycleQueue*/);
            }
            else
            {
                Generator.Release();
            }
        }
 // Token: 0x06005930 RID: 22832 RVA: 0x0018A4E0 File Offset: 0x001886E0
 internal void ClearItemContainer(object item, ItemsControl parentItemsControl)
 {
     if (VirtualizingPanel.GetIsVirtualizing(parentItemsControl))
     {
         Helper.StoreItemValues(parentItemsControl, this, item);
         VirtualizingPanel virtualizingPanel = base.ItemsHost as VirtualizingPanel;
         if (virtualizingPanel != null)
         {
             virtualizingPanel.OnClearChildrenInternal();
         }
         base.ItemContainerGenerator.RemoveAllInternal(true);
     }
     this.ContainsSelection = false;
 }
示例#9
0
		/// <summary>Builds the visual tree for the <see cref="T:System.Windows.Controls.GroupItem" /> when a new template is applied. </summary>
		// Token: 0x06004E07 RID: 19975 RVA: 0x0015FB34 File Offset: 0x0015DD34
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			this._header = (base.GetTemplateChild("PART_Header") as FrameworkElement);
			this._expander = Helper.FindTemplatedDescendant<Expander>(this, this);
			if (this._expander != null)
			{
				ItemsControl parentItemsControl = this.ParentItemsControl;
				if (parentItemsControl != null && VirtualizingPanel.GetIsVirtualizingWhenGrouping(parentItemsControl))
				{
					Helper.SetItemValuesOnContainer(parentItemsControl, this._expander, parentItemsControl.ItemContainerGenerator.ItemFromContainer(this));
				}
				this._expander.Expanded += GroupItem.OnExpanded;
			}
		}
        // Token: 0x06005934 RID: 22836 RVA: 0x0018A638 File Offset: 0x00188838
        private static void ExpandRecursive(TreeViewItem item)
        {
            if (item == null)
            {
                return;
            }
            if (!item.IsExpanded)
            {
                item.SetCurrentValueInternal(TreeViewItem.IsExpandedProperty, BooleanBoxes.TrueBox);
            }
            item.ApplyTemplate();
            ItemsPresenter itemsPresenter = (ItemsPresenter)item.Template.FindName("ItemsHost", item);

            if (itemsPresenter != null)
            {
                itemsPresenter.ApplyTemplate();
            }
            else
            {
                item.UpdateLayout();
            }
            VirtualizingPanel virtualizingPanel = item.ItemsHost as VirtualizingPanel;

            item.ItemsHost.EnsureGenerator();
            int i     = 0;
            int count = item.Items.Count;

            while (i < count)
            {
                TreeViewItem treeViewItem;
                if (virtualizingPanel != null)
                {
                    virtualizingPanel.BringIndexIntoView(i);
                    treeViewItem = (TreeViewItem)item.ItemContainerGenerator.ContainerFromIndex(i);
                }
                else
                {
                    treeViewItem = (TreeViewItem)item.ItemContainerGenerator.ContainerFromIndex(i);
                    treeViewItem.BringIntoView();
                }
                if (treeViewItem != null)
                {
                    TreeViewItem.ExpandRecursive(treeViewItem);
                }
                i++;
            }
        }
示例#11
0
        internal void PrepareItemContainer(object item, ItemsControl parentItemsControl)
        {
            //
            // Clear previously cached items sizes
            //
            Helper.ClearVirtualizingElement((IHierarchicalVirtualizationAndScrollInfo)this);

            IsVirtualizingPropagationHelper(parentItemsControl, this);

            //
            // ItemValueStorage:  restore saved values for this item onto the new container
            //
            if (VirtualizingPanel.GetIsVirtualizing(parentItemsControl))
            {
                Helper.SetItemValuesOnContainer(parentItemsControl, this, item);
            }
        }
示例#12
0
		// Token: 0x06004E08 RID: 19976 RVA: 0x0015FBB4 File Offset: 0x0015DDB4
		private static void OnExpanded(object sender, RoutedEventArgs e)
		{
			GroupItem groupItem = sender as GroupItem;
			if (groupItem != null && groupItem._expander != null && groupItem._expander.IsExpanded)
			{
				ItemsControl parentItemsControl = groupItem.ParentItemsControl;
				if (parentItemsControl != null && VirtualizingPanel.GetIsVirtualizing(parentItemsControl) && VirtualizingPanel.GetVirtualizationMode(parentItemsControl) == VirtualizationMode.Recycling)
				{
					ItemsPresenter itemsHostPresenter = groupItem.ItemsHostPresenter;
					if (itemsHostPresenter != null)
					{
						groupItem.InvalidateMeasure();
						Helper.InvalidateMeasureOnPath(itemsHostPresenter, groupItem, false);
					}
				}
			}
		}
        // Token: 0x0600510F RID: 20751 RVA: 0x0016BAE4 File Offset: 0x00169CE4
        private void AttachToOwner()
        {
            DependencyObject       templatedParent = base.TemplatedParent;
            ItemsControl           itemsControl    = templatedParent as ItemsControl;
            ItemContainerGenerator generator;

            if (itemsControl != null)
            {
                generator = itemsControl.ItemContainerGenerator;
            }
            else
            {
                GroupItem      groupItem      = templatedParent as GroupItem;
                ItemsPresenter itemsPresenter = ItemsPresenter.FromGroupItem(groupItem);
                if (itemsPresenter != null)
                {
                    itemsControl = itemsPresenter.Owner;
                }
                generator = ((groupItem != null) ? groupItem.Generator : null);
            }
            this._owner = itemsControl;
            this.UseGenerator(generator);
            GroupStyle         groupStyle = (this._generator != null) ? this._generator.GroupStyle : null;
            ItemsPanelTemplate itemsPanelTemplate;

            if (groupStyle != null)
            {
                itemsPanelTemplate = groupStyle.Panel;
                if (itemsPanelTemplate == null)
                {
                    if (VirtualizingPanel.GetIsVirtualizingWhenGrouping(itemsControl))
                    {
                        itemsPanelTemplate = GroupStyle.DefaultVirtualizingStackPanel;
                    }
                    else
                    {
                        itemsPanelTemplate = GroupStyle.DefaultStackPanel;
                    }
                }
            }
            else
            {
                itemsPanelTemplate = ((this._owner != null) ? this._owner.ItemsPanel : null);
            }
            this.Template = itemsPanelTemplate;
        }
        // Token: 0x06005A25 RID: 23077 RVA: 0x0018D700 File Offset: 0x0018B900
        private static void VirtualizationPropertyChangePropagationRecursive(DependencyObject parent, Panel itemsHost)
        {
            UIElementCollection internalChildren = itemsHost.InternalChildren;
            int count = internalChildren.Count;

            for (int i = 0; i < count; i++)
            {
                IHierarchicalVirtualizationAndScrollInfo hierarchicalVirtualizationAndScrollInfo = internalChildren[i] as IHierarchicalVirtualizationAndScrollInfo;
                if (hierarchicalVirtualizationAndScrollInfo != null)
                {
                    TreeViewItem.IsVirtualizingPropagationHelper(parent, (DependencyObject)hierarchicalVirtualizationAndScrollInfo);
                    Panel itemsHost2 = hierarchicalVirtualizationAndScrollInfo.ItemsHost;
                    if (itemsHost2 != null)
                    {
                        VirtualizingPanel.VirtualizationPropertyChangePropagationRecursive((DependencyObject)hierarchicalVirtualizationAndScrollInfo, itemsHost2);
                    }
                }
            }
        }
示例#15
0
        private static void OnExpanded(object sender, RoutedEventArgs e)
        {
            GroupItem groupItem = sender as GroupItem;

            if (groupItem != null && groupItem._expander != null && groupItem._expander.IsExpanded)
            {
                ItemsControl itemsControl = groupItem.ParentItemsControl;
                if (itemsControl != null && VirtualizingPanel.GetIsVirtualizing(itemsControl) && VirtualizingPanel.GetVirtualizationMode(itemsControl) == VirtualizationMode.Recycling)
                {
                    ItemsPresenter itemsHostPresenter = groupItem.ItemsHostPresenter;
                    if (itemsHostPresenter != null)
                    {
                        // In case a GroupItem that wasn't previously expanded is now
                        // recycled to represent an entity that is expanded, we face a situation
                        // where the ItemsHost isn't connected yet but we do need to synchronously
                        // remeasure the sub tree through the ItemsPresenter leading up to the
                        // ItemsHost panel. If we didnt do this the offsets could get skewed.
                        groupItem.InvalidateMeasure();
                        Helper.InvalidateMeasureOnPath(itemsHostPresenter, groupItem, false /*duringMeasure*/);
                    }
                }
            }
        }
示例#16
0
        internal void ClearItemContainer(object item, ItemsControl parentItemsControl)
        {
            if (Generator == null)
            {
                return;     // user-declared GroupItem - ignore (
            }
            //
            // ItemValueStorage:  save off values for this container if we're a virtualizing Group.
            //
            if (parentItemsControl != null && VirtualizingPanel.GetIsVirtualizingWhenGrouping(parentItemsControl))
            {
                Helper.StoreItemValues((IContainItemStorage)parentItemsControl, this, item);

                if (_expander != null)
                {
                    Helper.StoreItemValues((IContainItemStorage)parentItemsControl, _expander, item);
                }

                // Tell the panel to clear off all its containers.  This will cause this method to be called
                // recursively down the tree, allowing all descendent data to be stored before we save off
                // the ItemValueStorage DP for this container.

                VirtualizingPanel vp = _itemsHost as VirtualizingPanel;
                if (vp != null)
                {
                    vp.OnClearChildrenInternal();
                }

                Generator.RemoveAllInternal(true /*saveRecycleQueue*/);
            }
            else
            {
                Generator.Release();
            }

            ClearContentControl(item);
        }
示例#17
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _header = this.GetTemplateChild("PART_Header") as FrameworkElement;

            // GroupItem is generally re-templated to have an Expander.
            // Look for an Expander and store its Header size.g
            _expander = Helper.FindTemplatedDescendant <Expander>(this, this);

            //
            // ItemValueStorage:  restore saved values for this item onto the new container
            //
            if (_expander != null)
            {
                ItemsControl itemsControl = ParentItemsControl;
                if (itemsControl != null && VirtualizingPanel.GetIsVirtualizingWhenGrouping(itemsControl))
                {
                    Helper.SetItemValuesOnContainer(itemsControl, _expander, itemsControl.ItemContainerGenerator.ItemFromContainer(this));
                }

                _expander.Expanded += new RoutedEventHandler(OnExpanded);
            }
        }
 /// <summary>Adds the specified <see cref="T:System.Windows.UIElement" /> to the <see cref="P:System.Windows.Controls.Panel.InternalChildren" /> collection of a <see cref="T:System.Windows.Controls.VirtualizingPanel" /> element.</summary>
 /// <param name="child">The <see cref="T:System.Windows.UIElement" /> child to add to the collection.</param>
 // Token: 0x06005A28 RID: 23080 RVA: 0x0018D764 File Offset: 0x0018B964
 protected void AddInternalChild(UIElement child)
 {
     VirtualizingPanel.AddInternalChild(base.InternalChildren, child);
 }
 /// <summary>Adds the specified <see cref="T:System.Windows.UIElement" /> to the <see cref="P:System.Windows.Controls.Panel.InternalChildren" /> collection of a <see cref="T:System.Windows.Controls.VirtualizingPanel" /> element at the specified index position.</summary>
 /// <param name="index">The index position within the collection at which the child element is inserted.</param>
 /// <param name="child">The <see cref="T:System.Windows.UIElement" /> child to add to the collection.</param>
 // Token: 0x06005A29 RID: 23081 RVA: 0x0018D772 File Offset: 0x0018B972
 protected void InsertInternalChild(int index, UIElement child)
 {
     VirtualizingPanel.InsertInternalChild(base.InternalChildren, index, child);
 }
 /// <summary>Removes child elements from the <see cref="P:System.Windows.Controls.Panel.InternalChildren" /> collection.</summary>
 /// <param name="index">The beginning index position within the collection at which the first child element is removed.</param>
 /// <param name="range">The total number of child elements to remove from the collection.</param>
 // Token: 0x06005A2A RID: 23082 RVA: 0x0018D781 File Offset: 0x0018B981
 protected void RemoveInternalChildRange(int index, int range)
 {
     VirtualizingPanel.RemoveInternalChildRange(base.InternalChildren, index, range);
 }
        // Token: 0x06005A23 RID: 23075 RVA: 0x0018D664 File Offset: 0x0018B864
        private static object CoerceIsVirtualizingWhenGrouping(DependencyObject d, object baseValue)
        {
            bool isVirtualizing = VirtualizingPanel.GetIsVirtualizing(d);

            return(isVirtualizing && (bool)baseValue);
        }
示例#22
0
		// Token: 0x06004E0E RID: 19982 RVA: 0x0015FCB8 File Offset: 0x0015DEB8
		internal void PrepareItemContainer(object item, ItemsControl parentItemsControl)
		{
			if (this.Generator == null)
			{
				return;
			}
			if (this._itemsHost != null)
			{
				this._itemsHost.IsItemsHost = true;
			}
			bool flag = parentItemsControl != null && VirtualizingPanel.GetIsVirtualizingWhenGrouping(parentItemsControl);
			if (this.Generator != null)
			{
				if (!flag)
				{
					this.Generator.Release();
				}
				else
				{
					this.Generator.RemoveAllInternal(true);
				}
			}
			ItemContainerGenerator parent = this.Generator.Parent;
			GroupStyle groupStyle = parent.GroupStyle;
			Style style = groupStyle.ContainerStyle;
			if (style == null && groupStyle.ContainerStyleSelector != null)
			{
				style = groupStyle.ContainerStyleSelector.SelectStyle(item, this);
			}
			if (style != null)
			{
				if (!style.TargetType.IsInstanceOfType(this))
				{
					throw new InvalidOperationException(SR.Get("StyleForWrongType", new object[]
					{
						style.TargetType.Name,
						base.GetType().Name
					}));
				}
				base.Style = style;
				base.WriteInternalFlag2(InternalFlags2.IsStyleSetFromGenerator, true);
			}
			if (base.ContentIsItem || !base.HasNonDefaultValue(ContentControl.ContentProperty))
			{
				base.Content = item;
				base.ContentIsItem = true;
			}
			if (!base.HasNonDefaultValue(ContentControl.ContentTemplateProperty))
			{
				base.ContentTemplate = groupStyle.HeaderTemplate;
			}
			if (!base.HasNonDefaultValue(ContentControl.ContentTemplateSelectorProperty))
			{
				base.ContentTemplateSelector = groupStyle.HeaderTemplateSelector;
			}
			if (!base.HasNonDefaultValue(ContentControl.ContentStringFormatProperty))
			{
				base.ContentStringFormat = groupStyle.HeaderStringFormat;
			}
			Helper.ClearVirtualizingElement(this);
			if (flag)
			{
				Helper.SetItemValuesOnContainer(parentItemsControl, this, item);
				if (this._expander != null)
				{
					Helper.SetItemValuesOnContainer(parentItemsControl, this._expander, item);
				}
			}
		}
示例#23
0
 private void ItemsControl_OnLoaded(object sender, RoutedEventArgs e)
 {
     _virtualizingPanel = UI.FindChild<VirtualizingStackPanel>(ItemsControl, "VirtualizingStackPanel");
 }
示例#24
0
        //------------------------------------------------------
        //
        // Internal Methods
        //
        //------------------------------------------------------

        internal void PrepareItemContainer(object item, ItemsControl parentItemsControl)
        {
            if (Generator == null)
            {
                return;     // user-declared GroupItem - ignore (
            }
            // If a GroupItem is being recycled set back IsItemsHost
            if (_itemsHost != null)
            {
                _itemsHost.IsItemsHost = true;
            }

            bool isVirtualizingWhenGrouping = (parentItemsControl != null && VirtualizingPanel.GetIsVirtualizingWhenGrouping(parentItemsControl));

            // Release any previous containers. Also ensures Items and GroupStyle are hooked up correctly
            if (Generator != null)
            {
                if (!isVirtualizingWhenGrouping)
                {
                    Generator.Release();
                }
                else
                {
                    Generator.RemoveAllInternal(true /*saveRecycleQueue*/);
                }
            }

            ItemContainerGenerator generator  = Generator.Parent;
            GroupStyle             groupStyle = generator.GroupStyle;

            // apply the container style
            Style style = groupStyle.ContainerStyle;

            // no ContainerStyle set, try ContainerStyleSelector
            if (style == null)
            {
                if (groupStyle.ContainerStyleSelector != null)
                {
                    style = groupStyle.ContainerStyleSelector.SelectStyle(item, this);
                }
            }

            // apply the style, if found
            if (style != null)
            {
                // verify style is appropriate before applying it
                if (!style.TargetType.IsInstanceOfType(this))
                {
                    throw new InvalidOperationException(SR.Get(SRID.StyleForWrongType, style.TargetType.Name, this.GetType().Name));
                }

                this.Style = style;
                this.WriteInternalFlag2(InternalFlags2.IsStyleSetFromGenerator, true);
            }

            // forward the header template information
            if (ContentIsItem || !HasNonDefaultValue(ContentProperty))
            {
                this.Content  = item;
                ContentIsItem = true;
            }
            if (!HasNonDefaultValue(ContentTemplateProperty))
            {
                this.ContentTemplate = groupStyle.HeaderTemplate;
            }
            if (!HasNonDefaultValue(ContentTemplateSelectorProperty))
            {
                this.ContentTemplateSelector = groupStyle.HeaderTemplateSelector;
            }
            if (!HasNonDefaultValue(ContentStringFormatProperty))
            {
                this.ContentStringFormat = groupStyle.HeaderStringFormat;
            }

            //
            // Clear previously cached items sizes
            //
            Helper.ClearVirtualizingElement(this);

            //
            // ItemValueStorage:  restore saved values for this item onto the new container
            //
            if (isVirtualizingWhenGrouping)
            {
                Helper.SetItemValuesOnContainer(parentItemsControl, this, item);

                if (_expander != null)
                {
                    Helper.SetItemValuesOnContainer(parentItemsControl, _expander, item);
                }
            }
        }