Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Detect StrokeDashArray Border collection changes #10145

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/Controls/src/Core/Border.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable enable
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Runtime.CompilerServices;
using Microsoft.Maui.Controls.Shapes;
using Microsoft.Maui.Graphics;
Expand All @@ -11,6 +12,7 @@ namespace Microsoft.Maui.Controls
[ContentProperty(nameof(Content))]
public class Border : View, IContentView, IBorderView, IPaddingElement
{
float[]? _strokeDashPattern;
ReadOnlyCollection<Element>? _logicalChildren;

internal ObservableCollection<Element> InternalChildren { get; } = new();
Expand Down Expand Up @@ -131,7 +133,21 @@ public double StrokeMiterLimit
_ => LineJoin.Round
};

public float[]? StrokeDashPattern => StrokeDashArray?.ToFloatArray();
public float[]? StrokeDashPattern
{
get
{
if (StrokeDashArray is INotifyCollectionChanged oldCollection)
oldCollection.CollectionChanged -= OnStrokeDashArrayChanged;

_strokeDashPattern = StrokeDashArray?.ToFloatArray();

if (StrokeDashArray is INotifyCollectionChanged newCollection)
newCollection.CollectionChanged += OnStrokeDashArrayChanged;

return _strokeDashPattern;
}
}

float IStroke.StrokeDashOffset => (float)StrokeDashOffset;

Expand Down Expand Up @@ -202,5 +218,10 @@ protected override void OnPropertyChanged([CallerMemberName] string? propertyNam
propertyName == StrokeShapeProperty.PropertyName)
Handler?.UpdateValue(nameof(IBorderStroke.Shape));
}

void OnStrokeDashArrayChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
Handler?.UpdateValue(nameof(IBorderStroke.StrokeDashPattern));
}
}
}