chore: use AddClassHandler instead of OnPropertyChanged.
This commit is contained in:
1 parent
a28042e753
commit
8a31a48b29
2 files changed
+29
-38
No files matched your search
@@ -52,6 +52,7 @@ public class DashedBorder : Decorator
|
|||||||
BorderDashThicknessProperty,
|
BorderDashThicknessProperty,
|
||||||
BorderThicknessProperty
|
BorderThicknessProperty
|
||||||
);
|
);
|
||||||
|
|
||||||
AffectsRender<DashedBorder>(
|
AffectsRender<DashedBorder>(
|
||||||
BorderDashArrayProperty,
|
BorderDashArrayProperty,
|
||||||
BorderDashCapProperty,
|
BorderDashCapProperty,
|
||||||
@@ -60,6 +61,26 @@ public class DashedBorder : Decorator
|
|||||||
BorderBrushProperty,
|
BorderBrushProperty,
|
||||||
BackgroundProperty
|
BackgroundProperty
|
||||||
);
|
);
|
||||||
|
|
||||||
|
BorderThicknessProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
|
||||||
|
BorderDashThicknessProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
|
||||||
|
BorderBrushProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
|
||||||
|
BackgroundProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
|
||||||
|
BorderDashArrayProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
|
||||||
|
BorderDashCapProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
|
||||||
|
BorderDashOffsetProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnClearPenCache(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var border = (DashedBorder)d;
|
||||||
|
border._leftPenCache = null;
|
||||||
|
border._rightPenCache = null;
|
||||||
|
border._topPenCache = null;
|
||||||
|
border._bottomPenCache = null;
|
||||||
|
border._geometryPenCache = null;
|
||||||
|
border._backgroundGeometryCache = null;
|
||||||
|
border._borderGeometryCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double BorderDashThickness
|
public double BorderDashThickness
|
||||||
@@ -145,34 +166,6 @@ public class DashedBorder : Decorator
|
|||||||
_layoutThickness = new Thickness?();
|
_layoutThickness = new Thickness?();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
|
||||||
{
|
|
||||||
base.OnPropertyChanged(change);
|
|
||||||
|
|
||||||
string propertyName = change.Property.Name;
|
|
||||||
if (string.Equals(propertyName, nameof(BorderThickness)) ||
|
|
||||||
string.Equals(propertyName, nameof(BorderDashThickness)) ||
|
|
||||||
string.Equals(propertyName, nameof(BorderBrush)) ||
|
|
||||||
string.Equals(propertyName, nameof(Background)) ||
|
|
||||||
string.Equals(propertyName, nameof(BorderDashArray)) ||
|
|
||||||
string.Equals(propertyName, nameof(BorderDashCap)) ||
|
|
||||||
string.Equals(propertyName, nameof(BorderDashOffset)))
|
|
||||||
{
|
|
||||||
ClearCache();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ClearCache()
|
|
||||||
{
|
|
||||||
_leftPenCache = null;
|
|
||||||
_rightPenCache = null;
|
|
||||||
_topPenCache = null;
|
|
||||||
_bottomPenCache = null;
|
|
||||||
_geometryPenCache = null;
|
|
||||||
_backgroundGeometryCache = null;
|
|
||||||
_borderGeometryCache = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Render(DrawingContext context)
|
public override void Render(DrawingContext context)
|
||||||
{
|
{
|
||||||
var radii = CornerRadius;
|
var radii = CornerRadius;
|
||||||
|
|||||||
@@ -59,6 +59,14 @@ public class UniformSpacingPanel : Panel
|
|||||||
ItemHorizontalAlignmentProperty,
|
ItemHorizontalAlignmentProperty,
|
||||||
ItemVerticalAlignmentProperty
|
ItemVerticalAlignmentProperty
|
||||||
);
|
);
|
||||||
|
|
||||||
|
OrientationProperty.Changed.AddClassHandler<UniformSpacingPanel>(OnOrientationChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnOrientationChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var p = (UniformSpacingPanel)d;
|
||||||
|
p._orientation = e.GetNewValue<Orientation>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Orientation Orientation
|
public Orientation Orientation
|
||||||
@@ -117,16 +125,6 @@ public class UniformSpacingPanel : Panel
|
|||||||
|
|
||||||
private static double CoerceLength(AvaloniaObject _, double length) => length < 0 ? 0 : length;
|
private static double CoerceLength(AvaloniaObject _, double length) => length < 0 ? 0 : length;
|
||||||
|
|
||||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
|
||||||
{
|
|
||||||
base.OnPropertyChanged(change);
|
|
||||||
|
|
||||||
if (string.Equals(change.Property.Name, nameof(Orientation)))
|
|
||||||
{
|
|
||||||
_orientation = change.GetNewValue<Orientation>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Size MeasureOverride(Size availableSize)
|
protected override Size MeasureOverride(Size availableSize)
|
||||||
{
|
{
|
||||||
var curLineSize = new PanelUvSize(_orientation);
|
var curLineSize = new PanelUvSize(_orientation);
|
||||||
|
|||||||
Reference in new issue
Block a user