public override void OnApplyTemplate() { base.OnApplyTemplate(); Surface = (GetTemplateChild("PART_ContentHostNodes") as ItemsControl); Surface2 = (GetTemplateChild("PART_ContentHostLines") as ItemsControl); CalculateGenerations(); Surface.Width = Generations.Max(n => n.Nodes.Count) * HorizontalNodeSpace; Surface.Height = Generations.Count * VerticalNodeSpace; Surface2.Width = Surface.Width; Surface2.Height = Surface.Height; AllocateNodes(Nodes); AllocateLines(); }