Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Look here: <a href="http://blogs.claritycon.com/blogs/lee_roth/default.aspx" rel="nofollow noreferrer">http://blogs.claritycon.com/blogs/lee_roth/default.aspx</a></p> <p>I make recycling the following way:</p> <p>In <code>OnItemsChanged</code>, I only call <code>RemoveInternalChildRange</code>:</p> <pre><code>protected override void OnItemsChanged(object sender, ItemsChangedEventArgs args) { switch (args.Action) { case NotifyCollectionChangedAction.Remove: case NotifyCollectionChangedAction.Replace: RemoveInternalChildRange(args.Position.Index, args.ItemUICount); break; case NotifyCollectionChangedAction.Move: RemoveInternalChildRange(args.OldPosition.Index, args.ItemUICount); break; } } </code></pre> <p>In Measure override, I first add new items, then I remove the old ones. <strong>If you use recycling you have to know that the new-Flag that you get by calling GenerateNext is also false if you get a recycled container.</strong></p> <p>Here we add new Items:</p> <pre><code>GeneratorPosition start = ItemContainerGenerator.GeneratorPositionFromIndex(iFirstItemIndex); int iChildIndex = (start.Offset == 0) ? start.Index : start.Index + 1; using (ItemContainerGenerator.StartAt(start, GeneratorDirection.Forward, true)) { for (int i = iFirstItemIndex; i &lt;= iLastItemIndex; i++, iChildIndex++) { bool bNew; UIElement element = (UIElement)ItemContainerGenerator.GenerateNext(out bNew); //If we get a new instance if (bNew) { if (iChildIndex &gt;= Children.Count) AddInternalChild(element); else InsertInternalChild(iChildIndex, element); ItemContainerGenerator.PrepareItemContainer(element); } //If we get a recycled element else if (!InternalChildren.Contains(element)) { InsertInternalChild(iChildIndex, element); ItemContainerGenerator.PrepareItemContainer(element); } element.Measure(...); } } </code></pre> <p>After adding Items we remove the old Items:</p> <pre><code>for (int i = Children.Count - 1; i &gt;= 0; i--) { GeneratorPosition childGeneratorPosition = new GeneratorPosition(i, 0); int iIndex = ItemContainerGenerator.IndexFromGeneratorPosition(childGeneratorPosition); if (iIndex &lt; iFirstItemIndex || iIndex &gt; iLastItemIndex) { //remove() calls ItemContainerGenerator.remove() OR recycle(). Both works. remove(childGeneratorPosition, 1); RemoveInternalChildRange(i, 1); } } </code></pre> <p>I hope I could help you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload