Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0ddb607

Browse files
authoredJul 7, 2021
DrawingView.Points is now unique per instance (#1478)
1 parent 9f973a0 commit 0ddb607

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using NUnit.Framework;
2+
using Xamarin.CommunityToolkit.UI.Views;
3+
using Xamarin.Forms;
4+
5+
namespace Xamarin.CommunityToolkit.UnitTests.Views
6+
{
7+
public class DrawingView_Tests
8+
{
9+
[Test]
10+
public void AllInstancesShouldHaveTheirOwnPoints()
11+
{
12+
var drawingViewOne = new DrawingView();
13+
var drawingViewTwo = new DrawingView();
14+
15+
drawingViewOne.Points.Add(Point.Zero);
16+
17+
drawingViewTwo.Points.Clear();
18+
19+
Assert.IsNotEmpty(drawingViewOne.Points);
20+
Assert.IsFalse(ReferenceEquals(drawingViewOne.Points, drawingViewTwo.Points));
21+
}
22+
}
23+
}

‎src/CommunityToolkit/Xamarin.CommunityToolkit/Views/DrawingView/DrawingView.shared.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class DrawingView : View
2727
BindableProperty.Create(nameof(ClearOnFinish), typeof(bool), typeof(DrawingView), default(bool));
2828

2929
public static readonly BindableProperty PointsProperty = BindableProperty.Create(
30-
nameof(Points), typeof(ObservableCollection<Point>), typeof(DrawingView), new ObservableCollection<Point>(), BindingMode.TwoWay);
30+
nameof(Points), typeof(ObservableCollection<Point>), typeof(DrawingView), default, BindingMode.TwoWay);
3131

3232
public static readonly BindableProperty DrawingCompletedCommandProperty = BindableProperty.Create(
3333
nameof(DrawingCompletedCommand), typeof(ICommand), typeof(DrawingView));
@@ -74,6 +74,11 @@ public bool ClearOnFinish
7474
set => SetValue(ClearOnFinishProperty, value);
7575
}
7676

77+
public DrawingView()
78+
{
79+
Points = new ObservableCollection<Point>();
80+
}
81+
7782
static object CoerceValue(BindableObject bindable, object value)
7883
=> ((DrawingView)bindable).CoerceValue((int)value);
7984

0 commit comments

Comments
 (0)
This repository has been archived.