/// <summary> /// Handles the property changed call back of the number of levels. /// </summary> /// <param name="d">Dependency object whose property got changed.</param> /// <param name="e">EventArgs containing instance data.</param> private static void NumberOfLevels_Callback(DependencyObject d, DependencyPropertyChangedEventArgs e) { LevelOfDetail lodControl = d as LevelOfDetail; if (lodControl != null && e.OldValue != e.NewValue && lodControl.tickContainer != null) { lodControl.OnNumberOfLevelsChange(); } }
/// <summary> /// Validates the data. /// </summary> private void Validate() { if (this.CurrentLevel > this.NumberOfLevels) { LevelOfDetail.RaiseArgumentException("CurrentLevel", "CurrentLevel is more than NumberOfLevels."); } if (this.CurrentLevel < 0) { LevelOfDetail.RaiseArgumentException("CurrentLevel", "Invalid CurrentLevel."); } if (this.NumberOfLevels < 0) { LevelOfDetail.RaiseArgumentException("NumberOfLevels", "Invalid NumberOfLevels."); } }
/// <summary> /// Handles the property changed call back of the current level. /// </summary> /// <param name="d">Dependency object whose property got changed.</param> /// <param name="e">EventArgs containing instance data.</param> private static void CurrentLevelChanged_Callback(DependencyObject d, DependencyPropertyChangedEventArgs e) { LevelOfDetail lodControl = d as LevelOfDetail; if (lodControl != null && lodControl.tickContainer != null && !lodControl.coercing) { if (lodControl.CurrentLevel < 1 || lodControl.CurrentLevel > lodControl.NumberOfLevels) { lodControl.coercing = true; lodControl.CurrentLevel = (int)e.OldValue; lodControl.coercing = false; } else { lodControl.OnCurrentLevelChange((int)e.OldValue, (int)e.NewValue); } } }
/// <summary> /// Overridden. Applies the specified template. /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); this.Validate(); this.incrementButton = this.GetTemplateChild(IncrementButtonElementName) as Button; this.decrementButton = this.GetTemplateChild(DecrementButtonElementName) as Button; this.tickContainer = this.GetTemplateChild(TickContainerElementName) as Panel; LevelOfDetail.AssertTemplatePart(this.incrementButton, IncrementButtonElementName); LevelOfDetail.AssertTemplatePart(this.decrementButton, DecrementButtonElementName); LevelOfDetail.AssertTemplatePart(this.tickContainer, TickContainerElementName); this.incrementButton.Click += new RoutedEventHandler(this.IncrementButton_Click); this.decrementButton.Click += new RoutedEventHandler(this.DecrementButton_Click); #if !SILVERLIGHT this.UpdateContentMargins(); #endif this.OnNumberOfLevelsChange(); }