using System.Windows; namespace MuchInfo.Chart.WPF.Helpers { #region Enumerations public enum InvalidationType { Measure = 1, Arrange = 2, Visual = 4, ParentMeasure = 8, ParentArrange = 16 } #endregion Enumerations public static class ElementInvalidator { #region Methods #region Public Static Methods public static void Invalidate(FrameworkElement target, InvalidationType invalidationTypes) { if (target != null) { if ((invalidationTypes & InvalidationType.Measure) != (InvalidationType)0) { target.InvalidateMeasure(); } if ((invalidationTypes & InvalidationType.Arrange) != (InvalidationType)0) { target.InvalidateArrange(); } if ((invalidationTypes & InvalidationType.Visual) != (InvalidationType)0) { target.InvalidateVisual(); } var frameworkElement = target.Parent as FrameworkElement; if (frameworkElement != null) { if ((invalidationTypes & InvalidationType.ParentMeasure) != (InvalidationType)0) { frameworkElement.InvalidateMeasure(); } if ((invalidationTypes & InvalidationType.ParentArrange) != (InvalidationType)0) { frameworkElement.InvalidateArrange(); } } } } public static void PropertyChanged_InvalidateArrange(DependencyObject d, DependencyPropertyChangedEventArgs e) { ElementInvalidator.Invalidate(d as FrameworkElement, InvalidationType.Arrange); } public static void PropertyChanged_InvalidateMeasure(DependencyObject d, DependencyPropertyChangedEventArgs e) { ElementInvalidator.Invalidate(d as FrameworkElement, InvalidationType.Measure); } public static void PropertyChanged_InvalidateMeasureArrange(DependencyObject d, DependencyPropertyChangedEventArgs e) { ElementInvalidator.Invalidate(d as FrameworkElement, InvalidationType.Measure | InvalidationType.Arrange); } public static void PropertyChanged_InvalidateMeasureArrangeVisual(DependencyObject d, DependencyPropertyChangedEventArgs e) { ElementInvalidator.Invalidate(d as FrameworkElement, InvalidationType.Measure | InvalidationType.Arrange | InvalidationType.Visual); } public static void PropertyChanged_InvalidateMeasureArrangeVisualParentMeasureArrange(DependencyObject d, DependencyPropertyChangedEventArgs e) { ElementInvalidator.Invalidate(d as FrameworkElement, InvalidationType.Measure | InvalidationType.Arrange | InvalidationType.Visual | InvalidationType.ParentMeasure | InvalidationType.ParentArrange); } public static void PropertyChanged_InvalidateParentArrange(DependencyObject d, DependencyPropertyChangedEventArgs e) { ElementInvalidator.Invalidate(d as FrameworkElement, InvalidationType.ParentArrange); } public static void PropertyChanged_InvalidateParentMeasure(DependencyObject d, DependencyPropertyChangedEventArgs e) { ElementInvalidator.Invalidate(d as FrameworkElement, InvalidationType.ParentMeasure); } public static void PropertyChanged_InvalidateVisual(DependencyObject d, DependencyPropertyChangedEventArgs e) { ElementInvalidator.Invalidate(d as FrameworkElement, InvalidationType.Visual); } #endregion Public Static Methods #endregion Methods } }