public void CachePhaseElement(FrameworkElement phaseElement, int phase) { if (phase < 0) { throw new ArgumentOutOfRangeException("phase"); } if (phase <= 0) { return; } UIElement contentTemplateRoot = IncrementalUpdater.FindContentTemplateRoot(phaseElement); if (contentTemplateRoot != null) { // get the cache for this element ElementCacheRecord elementCacheRecord; if (!this.elementCache.TryGetValue(contentTemplateRoot, out elementCacheRecord)) { elementCacheRecord = new ElementCacheRecord(); this.elementCache.Add(contentTemplateRoot, elementCacheRecord); } // get the cache for this phase int phaseIndex = elementCacheRecord.Phases.BinarySearch(phase); if (phaseIndex < 0) { // not found - insert phaseIndex = ~phaseIndex; elementCacheRecord.Phases.Insert(phaseIndex, phase); elementCacheRecord.ElementsByPhase.Insert(phaseIndex, new List <PhasedElementRecord>()); } List <PhasedElementRecord> phasedElementRecords = elementCacheRecord.ElementsByPhase[phaseIndex]; // first see if the element is already there for (int i = 0; i < phasedElementRecords.Count; i++) { if (phasedElementRecords[i].FrameworkElement == phaseElement) { return; } } // insert the element phasedElementRecords.Add(new PhasedElementRecord(phaseElement)); } }
public void UncachePhaseElement(FrameworkElement phaseElement, int phase) { if (phase <= 0) { return; } UIElement contentTemplateRoot = IncrementalUpdater.FindContentTemplateRoot(phaseElement); if (contentTemplateRoot != null) { // get the cache for this element ElementCacheRecord elementCacheRecord; if (this.elementCache.TryGetValue(contentTemplateRoot, out elementCacheRecord)) { // get the cache for this phase int phaseIndex = elementCacheRecord.Phases.BinarySearch(phase); if (phaseIndex >= 0) { // remove the element: the linear search here is not spectacular but the list should be very short List <PhasedElementRecord> phasedElementRecords = elementCacheRecord.ElementsByPhase[phaseIndex]; for (int i = 0; i < phasedElementRecords.Count; i++) { if (phasedElementRecords[i].FrameworkElement == phaseElement) { phasedElementRecords[i].ThawAndShow(); phasedElementRecords.RemoveAt(i); if (phasedElementRecords.Count == 0) { elementCacheRecord.Phases.RemoveAt(phaseIndex); elementCacheRecord.ElementsByPhase.RemoveAt(phaseIndex); } } } } } } }