diff --git a/src/Avalonia.Layout/Layoutable.cs b/src/Avalonia.Layout/Layoutable.cs index 1eee2de042..d5e3a1631e 100644 --- a/src/Avalonia.Layout/Layoutable.cs +++ b/src/Avalonia.Layout/Layoutable.cs @@ -445,9 +445,14 @@ namespace Avalonia.Layout protected static void AffectsMeasure(params AvaloniaProperty[] properties) where T : class, ILayoutable { + void Invalidate(AvaloniaPropertyChangedEventArgs e) + { + (e.Sender as T)?.InvalidateMeasure(); + } + foreach (var property in properties) { - property.Changed.Subscribe(AffectsMeasureInvalidate); + property.Changed.Subscribe(Invalidate); } } @@ -477,9 +482,14 @@ namespace Avalonia.Layout protected static void AffectsArrange(params AvaloniaProperty[] properties) where T : class, ILayoutable { + void Invalidate(AvaloniaPropertyChangedEventArgs e) + { + (e.Sender as T)?.InvalidateArrange(); + } + foreach (var property in properties) { - property.Changed.Subscribe(AffectsArrangeInvalidate); + property.Changed.Subscribe(Invalidate); } } @@ -664,28 +674,6 @@ namespace Avalonia.Layout base.OnVisualParentChanged(oldParent, newParent); } - /// - /// Calls on the control on which a property changed. - /// - /// The event args. - private static void AffectsMeasureInvalidate(AvaloniaPropertyChangedEventArgs e) - where T : class, ILayoutable - { - var control = e.Sender as T; - control?.InvalidateMeasure(); - } - - /// - /// Calls on the control on which a property changed. - /// - /// The event args. - private static void AffectsArrangeInvalidate(AvaloniaPropertyChangedEventArgs e) - where T : class, ILayoutable - { - var control = e.Sender as T; - control?.InvalidateArrange(); - } - /// /// Tests whether any of a 's properties include negative values, /// a NaN or Infinity. diff --git a/src/Avalonia.Visuals/Visual.cs b/src/Avalonia.Visuals/Visual.cs index 6915ec596b..1ac83e41a5 100644 --- a/src/Avalonia.Visuals/Visual.cs +++ b/src/Avalonia.Visuals/Visual.cs @@ -340,9 +340,14 @@ namespace Avalonia protected static void AffectsRender(params AvaloniaProperty[] properties) where T : class, IVisual { + void Invalidate(AvaloniaPropertyChangedEventArgs e) + { + (e.Sender as T)?.InvalidateVisual(); + } + foreach (var property in properties) { - property.Changed.Subscribe(AffectsRenderInvalidate); + property.Changed.Subscribe(Invalidate); } } @@ -430,16 +435,6 @@ namespace Avalonia RaisePropertyChanged(VisualParentProperty, oldParent, newParent, BindingPriority.LocalValue); } - /// - /// Called when a property changes that should invalidate the visual. - /// - /// The event args. - private static void AffectsRenderInvalidate(AvaloniaPropertyChangedEventArgs e) - where T : class, IVisual - { - (e.Sender as T)?.InvalidateVisual(); - } - /// /// Gets the visual offset from the specified ancestor. ///