public override void OnApplyTemplate() { base.OnApplyTemplate(); if (this.RootElement != null) { this.RootElement.SizeChanged -= new SizeChangedEventHandler(RootElement_SizeChanged); } RootElement = (StackPanel)Template.FindName("RootElement", this); StarTemplate = RootElement.TryFindResource(new ComponentResourceKey(typeof(RatingControl), "StarTemplate")) as ControlTemplate; UpdateStarList(); if (this.RootElement != null) { this.RootElement.SizeChanged += new SizeChangedEventHandler(RootElement_SizeChanged); } }