Skip to content

Commit 854089f

Browse files
authored
Merge pull request #9 from tiny-isle/ensure-foreground-exist
Initialize stroke and geometry when control attaches to the visual tree
2 parents fd0008a + 1b80f05 commit 854089f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Lucide.Avalonia/LucideIcon.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
8585
protected override Size MeasureOverride(Size availableSize) => GetIconSize();
8686

8787
protected override Size ArrangeOverride(Size finalSize) => GetIconSize();
88+
89+
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
90+
{
91+
base.OnAttachedToVisualTree(e);
92+
93+
var brush = Foreground;
94+
var width = StrokeWidth;
95+
96+
if (_stroke == null && brush != null)
97+
{
98+
_stroke = new Pen(brush, width, null, PenLineCap.Round, PenLineJoin.Round);
99+
}
100+
101+
var kind = Kind;
102+
103+
if (_geometry == null && kind != null)
104+
{
105+
_geometry = IconToGeometry.CreateGeometry(kind.Value);
106+
}
107+
}
88108

89109
public override void Render(DrawingContext context)
90110
{

0 commit comments

Comments
 (0)