Skip to content

Commit 8a31a48

Browse files
committed
chore: use AddClassHandler instead of OnPropertyChanged.
1 parent a28042e commit 8a31a48

File tree

2 files changed

+29
-38
lines changed

2 files changed

+29
-38
lines changed

src/Avalonia/HandyControl_Avalonia/Controls/Other/DashedBorder.cs

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static DashedBorder()
5252
BorderDashThicknessProperty,
5353
BorderThicknessProperty
5454
);
55+
5556
AffectsRender<DashedBorder>(
5657
BorderDashArrayProperty,
5758
BorderDashCapProperty,
@@ -60,6 +61,26 @@ static DashedBorder()
6061
BorderBrushProperty,
6162
BackgroundProperty
6263
);
64+
65+
BorderThicknessProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
66+
BorderDashThicknessProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
67+
BorderBrushProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
68+
BackgroundProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
69+
BorderDashArrayProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
70+
BorderDashCapProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
71+
BorderDashOffsetProperty.Changed.AddClassHandler<DashedBorder>(OnClearPenCache);
72+
}
73+
74+
private static void OnClearPenCache(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
75+
{
76+
var border = (DashedBorder)d;
77+
border._leftPenCache = null;
78+
border._rightPenCache = null;
79+
border._topPenCache = null;
80+
border._bottomPenCache = null;
81+
border._geometryPenCache = null;
82+
border._backgroundGeometryCache = null;
83+
border._borderGeometryCache = null;
6384
}
6485

6586
public double BorderDashThickness
@@ -145,34 +166,6 @@ private void VerifyScale()
145166
_layoutThickness = new Thickness?();
146167
}
147168

148-
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
149-
{
150-
base.OnPropertyChanged(change);
151-
152-
string propertyName = change.Property.Name;
153-
if (string.Equals(propertyName, nameof(BorderThickness)) ||
154-
string.Equals(propertyName, nameof(BorderDashThickness)) ||
155-
string.Equals(propertyName, nameof(BorderBrush)) ||
156-
string.Equals(propertyName, nameof(Background)) ||
157-
string.Equals(propertyName, nameof(BorderDashArray)) ||
158-
string.Equals(propertyName, nameof(BorderDashCap)) ||
159-
string.Equals(propertyName, nameof(BorderDashOffset)))
160-
{
161-
ClearCache();
162-
}
163-
}
164-
165-
private void ClearCache()
166-
{
167-
_leftPenCache = null;
168-
_rightPenCache = null;
169-
_topPenCache = null;
170-
_bottomPenCache = null;
171-
_geometryPenCache = null;
172-
_backgroundGeometryCache = null;
173-
_borderGeometryCache = null;
174-
}
175-
176169
public override void Render(DrawingContext context)
177170
{
178171
var radii = CornerRadius;

src/Avalonia/HandyControl_Avalonia/Controls/Panel/UniformSpacingPanel.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ static UniformSpacingPanel()
5959
ItemHorizontalAlignmentProperty,
6060
ItemVerticalAlignmentProperty
6161
);
62+
63+
OrientationProperty.Changed.AddClassHandler<UniformSpacingPanel>(OnOrientationChanged);
64+
}
65+
66+
private static void OnOrientationChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
67+
{
68+
var p = (UniformSpacingPanel)d;
69+
p._orientation = e.GetNewValue<Orientation>();
6270
}
6371

6472
public Orientation Orientation
@@ -117,16 +125,6 @@ public VerticalAlignment? ItemVerticalAlignment
117125

118126
private static double CoerceLength(AvaloniaObject _, double length) => length < 0 ? 0 : length;
119127

120-
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
121-
{
122-
base.OnPropertyChanged(change);
123-
124-
if (string.Equals(change.Property.Name, nameof(Orientation)))
125-
{
126-
_orientation = change.GetNewValue<Orientation>();
127-
}
128-
}
129-
130128
protected override Size MeasureOverride(Size availableSize)
131129
{
132130
var curLineSize = new PanelUvSize(_orientation);

0 commit comments

Comments
 (0)