public void PhaseElement(UIElement element, VirtualizationInfo virtInfo) { var dataTemplateComponent = virtInfo.DataTemplateComponent; var nextPhase = virtInfo.Phase; bool shouldPhase = false; if (nextPhase > 0) { if (dataTemplateComponent != null) { // Perf optimization: RecyclingElementFactory sets up the virtualization info so we don't need to update it here. shouldPhase = true; } else { throw new InvalidOperationException("Phase was set on virtualization info, but dataTemplateComponent was not."); } } else if (nextPhase == VirtualizationInfo.PhaseNotSpecified) { // If virtInfo.Phase is not specified, virtInfo.DataTemplateComponent cannot be valid. global::System.Diagnostics.Debug.Assert(dataTemplateComponent == null); // ItemsRepeater might be using a custom view generator in which case, virtInfo would not be bootstrapped. // In this case, fallback to querying for the data template component and setup virtualization info now. dataTemplateComponent = XamlBindingHelper.GetDataTemplateComponent(element); if (dataTemplateComponent != null) { // Clear out old data. dataTemplateComponent.Recycle(); nextPhase = VirtualizationInfo.PhaseReachedEnd; var index = virtInfo.Index; var data = m_owner.ItemsSourceView.GetAt(index); // Run Phase 0 dataTemplateComponent.ProcessBindings(data, index, 0 /* currentPhase */, out nextPhase); // Update phase on virtInfo. Set data and templateComponent only if x:Phase was used. virtInfo.UpdatePhasingInfo(nextPhase, nextPhase > 0 ? data : null, nextPhase > 0 ? dataTemplateComponent : null); shouldPhase = nextPhase > 0; } } if (shouldPhase) { // Insert at the top since we remove from bottom during DoPhasedWorkCallback. This keeps the ordering of items // the same as the order in which items are realized. m_pendingElements.Insert(0, new ElementInfo(element, virtInfo)); RegisterForCallback(); } }
protected override void RecycleElementCore(ElementFactoryRecycleArgs args) { XamlBindingHelper.GetDataTemplateComponent(args.Element).Recycle(); _recyclePool.PutElement(args.Element, key, args.Parent); }
public static IDataTemplateComponent GetDataTemplateComponent(UIElement element) => XamlBindingHelper.GetDataTemplateComponent(element);