Browse Source

Invalidate controls when brush changed.

pull/1881/head
Steven Kirk 8 years ago
parent
commit
a5a5b36ddc
  1. 3
      src/Avalonia.Controls/Border.cs
  2. 1
      src/Avalonia.Controls/Panel.cs
  3. 3
      src/Avalonia.Controls/Presenters/ContentPresenter.cs
  4. 4
      src/Avalonia.Controls/Shapes/Shape.cs
  5. 2
      src/Avalonia.Controls/TextBlock.cs
  6. 40
      src/Avalonia.Visuals/Visual.cs

3
src/Avalonia.Controls/Border.cs

@ -43,8 +43,9 @@ namespace Avalonia.Controls
/// </summary>
static Border()
{
AffectsRender(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty);
AffectsRender(BorderThicknessProperty, CornerRadiusProperty);
AffectsMeasure(BorderThicknessProperty);
BrushAffectsRender<Border>(BackgroundProperty, BorderBrushProperty);
}
/// <summary>

1
src/Avalonia.Controls/Panel.cs

@ -30,6 +30,7 @@ namespace Avalonia.Controls
/// </summary>
static Panel()
{
BrushAffectsRender<Panel>(BackgroundProperty);
ClipToBoundsProperty.OverrideDefaultValue<Panel>(true);
}

3
src/Avalonia.Controls/Presenters/ContentPresenter.cs

@ -90,8 +90,9 @@ namespace Avalonia.Controls.Presenters
/// </summary>
static ContentPresenter()
{
AffectsRender(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty, CornerRadiusProperty);
AffectsRender(BorderThicknessProperty, CornerRadiusProperty);
AffectsMeasure(BorderThicknessProperty, PaddingProperty);
BrushAffectsRender<ContentPresenter>(BackgroundProperty, BorderBrushProperty);
ContentProperty.Changed.AddClassHandler<ContentPresenter>(x => x.ContentChanged);
ContentTemplateProperty.Changed.AddClassHandler<ContentPresenter>(x => x.ContentChanged);
TemplatedParentProperty.Changed.AddClassHandler<ContentPresenter>(x => x.TemplatedParentChanged);

4
src/Avalonia.Controls/Shapes/Shape.cs

@ -30,11 +30,11 @@ namespace Avalonia.Controls.Shapes
private Geometry _renderedGeometry;
bool _calculateTransformOnArrange = false;
static Shape()
{
AffectsMeasure(StretchProperty, StrokeThicknessProperty);
AffectsRender(FillProperty, StrokeProperty, StrokeDashArrayProperty);
AffectsRender(StrokeDashArrayProperty);
BrushAffectsRender<Shape>(FillProperty, StrokeProperty);
}
public Geometry DefiningGeometry

2
src/Avalonia.Controls/TextBlock.cs

@ -99,10 +99,10 @@ namespace Avalonia.Controls
static TextBlock()
{
ClipToBoundsProperty.OverrideDefaultValue<TextBlock>(true);
AffectsRender(ForegroundProperty);
AffectsRender(FontWeightProperty);
AffectsRender(FontSizeProperty);
AffectsRender(FontStyleProperty);
BrushAffectsRender<TextBlock>(BackgroundProperty, ForegroundProperty);
}
/// <summary>

40
src/Avalonia.Visuals/Visual.cs

@ -328,6 +328,44 @@ namespace Avalonia
}
}
/// <summary>
/// Indicates that a brush property change should cause <see cref="InvalidateVisual"/> to be
/// called.
/// </summary>
/// <param name="properties">The properties.</param>
/// <remarks>
/// This method should be called in a control's static constructor with each property
/// on the control which when changed should cause a redraw. It not only triggers an
/// invalidation when the property itself changes, but also when the brush raises
/// the <see cref="IMutableBrush.Changed"/> event.
/// </remarks>
protected static void BrushAffectsRender<T>(params AvaloniaProperty<IBrush>[] properties)
where T : Visual
{
void Invalidate(AvaloniaPropertyChangedEventArgs e)
{
if (e.Sender is T sender)
{
if (e.OldValue is IMutableBrush oldValue)
{
oldValue.Changed -= sender.BrushChanged;
}
if (e.NewValue is IMutableBrush newValue)
{
newValue.Changed += sender.BrushChanged;
}
sender.InvalidateVisual();
}
}
foreach (var property in properties)
{
property.Changed.Subscribe(Invalidate);
}
}
/// <summary>
/// Calls the <see cref="OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)"/> method
/// for this control and all of its visual descendants.
@ -530,6 +568,8 @@ namespace Avalonia
OnVisualParentChanged(old, value);
}
private void BrushChanged(object sender, EventArgs e) => InvalidateVisual();
/// <summary>
/// Called when the <see cref="VisualChildren"/> collection changes.
/// </summary>

Loading…
Cancel
Save