private void CreateItemTemplateControl(PageData page, int level, bool hasChildren, PageReference currentPageLink) { PageTemplateContainer template = new PageTemplateContainer(page, level, hasChildren); if (level == 1) { if (page.PageLink.CompareToIgnoreWorkID(currentPageLink) && this.IsExpanded(page.PageLink)) { this.InstantiateSelectedExpandedTopTemplate(template); } else if (this.IsExpanded(page.PageLink)) { this.InstantiateExpandedTopTemplate(template); } else if (page.PageLink.CompareToIgnoreWorkID(currentPageLink)) { this.InstantiateSelectedTopTemplate(template); } else { this.InstantiateTopTemplate(template); } } else if (page.PageLink.CompareToIgnoreWorkID(currentPageLink) && this.IsExpanded(page.PageLink)) { this.InstantiateSelectedExpandedItemTemplate(template); } else if (this.IsExpanded(page.PageLink)) { this.InstantiateExpandedItemTemplate(template); } else if (page.PageLink.CompareToIgnoreWorkID(currentPageLink)) { this.InstantiateSelectedItemTemplate(template); } else { this.InstantiateItemTemplate(template); } if (ItemDataBound != null) { var pageTreeEventArgs = new PageTreeEventArgs { Item = template, DataItem = page }; ItemDataBound.Invoke(this, pageTreeEventArgs); } this.Controls.Add(template); }