private static Panel LoadPanelTemplate(ItemsPanelTemplate panelTemplate) { var panel = (Panel)panelTemplate.LoadContent(); panel.IsItemsHost = false; //set by ItemPanelTemplate, we need to reset it return(panel); }
protected override void OnItemsPanelChanged(ItemsPanelTemplate oldItemsPanel, ItemsPanelTemplate newItemsPanel) { // This is not the actual WrappableStackPanel that will be used as the ItemsPanel. // This is another instance, and I use the field only for existence, not reference. isWrappableStackPanel = (newItemsPanel.LoadContent() as WrappableStackPanel) != null; base.OnItemsPanelChanged(oldItemsPanel, newItemsPanel); }
private static CodeExpression GetItemsPanelTemplateValueExpression(CodeTypeDeclaration parentClass, CodeMemberMethod method, object value, string baseName) { ItemsPanelTemplate template = value as ItemsPanelTemplate; DependencyObject content = template.LoadContent(); string variableName = baseName + "_ipt"; string creator = CodeComHelper.GenerateTemplate(parentClass, method, content, variableName); CodeVariableDeclarationStatement templateVar = new CodeVariableDeclarationStatement( "ControlTemplate", variableName, new CodeObjectCreateExpression("ControlTemplate", new CodeSnippetExpression(creator))); method.Statements.Add(templateVar); return(new CodeVariableReferenceExpression(variableName)); }
public void ApplyTemplate(ItemsPanelTemplate template) { DetachScrolling(); FrameworkElement content = template.LoadContent() as FrameworkElement; FrameworkElement oldTemplateControl = TemplateControl; if (oldTemplateControl != null) oldTemplateControl.CleanupAndDispose(); TemplateControl = content; if (content == null) _itemsHostPanel = null; else { content.LogicalParent = this; _itemsHostPanel = content.FindElement(ItemsHostMatcher.Instance) as Panel; } AttachScrolling(); }