protected override void RecycleElementCore(ElementFactoryRecycleArgs args) { var element = args.Element; var key = RecyclePool.GetReuseKey(element); m_recyclePool.PutElement(element, key, args.Parent); }
protected override UIElement GetElementCore(ElementFactoryGetArgs args) { if (m_templates is null || m_templates.Count == 0) { throw new InvalidOperationException("Templates property cannot be null or empty."); } var winrtOwner = args.Parent; var templateKey = m_templates.Count == 1 ? m_templates.First().Key : OnSelectTemplateKeyCore(args.Data, winrtOwner); if (string.IsNullOrEmpty(templateKey)) { // Note: We could allow null/whitespace, which would work as long as // the recycle pool is not shared. in order to make this work in all cases // currently we validate that a valid template key is provided. throw new InvalidOperationException("Template key cannot be empty or null."); } // Get an element from the Recycle Pool or create one var element = m_recyclePool.TryGetElement(templateKey, winrtOwner) as FrameworkElement; if (element is null) { // No need to call HasKey if there is only one template. if (m_templates.Count > 1 && !m_templates.ContainsKey(templateKey)) { string message = "No templates of key " + templateKey + " were found in the templates collection."; throw new InvalidOperationException(message); } var dataTemplate = m_templates[templateKey]; element = dataTemplate.LoadContent() as FrameworkElement; // Associate ReuseKey with element RecyclePool.SetReuseKey(element, templateKey); } return(element); }
public static void SetPoolInstance(DataTemplate dataTemplate, RecyclePool value) => dataTemplate.SetValue(PoolInstanceProperty, value);