-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Path.cs
118 lines (98 loc) · 3.6 KB
/
Path.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#nullable disable
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Microsoft.Maui.Graphics;
namespace Microsoft.Maui.Controls.Shapes
{
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/Path.xml" path="Type[@FullName='Microsoft.Maui.Controls.Shapes.Path']/Docs/*" />
public sealed partial class Path : Shape, IShape
{
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/Path.xml" path="//Member[@MemberName='.ctor'][1]/Docs/*" />
public Path() : base()
{
}
public Path(Geometry data) : this()
{
Data = data;
}
/// <summary>Bindable property for <see cref="Data"/>.</summary>
public static readonly BindableProperty DataProperty =
BindableProperty.Create(nameof(Data), typeof(Geometry), typeof(Path), null,
propertyChanged: OnGeometryPropertyChanged);
/// <summary>Bindable property for <see cref="RenderTransform"/>.</summary>
public static readonly BindableProperty RenderTransformProperty =
BindableProperty.Create(nameof(RenderTransform), typeof(Transform), typeof(Path), null,
propertyChanged: OnTransformPropertyChanged);
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/Path.xml" path="//Member[@MemberName='Data']/Docs/*" />
[System.ComponentModel.TypeConverter(typeof(PathGeometryConverter))]
public Geometry Data
{
set { SetValue(DataProperty, value); }
get { return (Geometry)GetValue(DataProperty); }
}
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/Path.xml" path="//Member[@MemberName='RenderTransform']/Docs/*" />
public Transform RenderTransform
{
set { SetValue(RenderTransformProperty, value); }
get { return (Transform)GetValue(RenderTransformProperty); }
}
static void OnGeometryPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
if (oldValue != null)
{
(oldValue as Geometry).PropertyChanged -= (bindable as Path).OnGeometryPropertyChanged;
if (oldValue is PathGeometry pathGeometry)
pathGeometry.InvalidatePathGeometryRequested -= (bindable as Path).OnInvalidatePathGeometryRequested;
}
if (newValue != null)
{
(newValue as Geometry).PropertyChanged += (bindable as Path).OnGeometryPropertyChanged;
if (newValue is PathGeometry pathGeometry)
pathGeometry.InvalidatePathGeometryRequested += (bindable as Path).OnInvalidatePathGeometryRequested;
}
}
static void OnTransformPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
if (oldValue != null)
{
(oldValue as Transform).PropertyChanged -= (bindable as Path).OnTransformPropertyChanged;
}
if (newValue != null)
{
(newValue as Transform).PropertyChanged += (bindable as Path).OnTransformPropertyChanged;
}
}
void OnGeometryPropertyChanged(object sender, PropertyChangedEventArgs args)
{
OnPropertyChanged(nameof(Data));
}
void OnInvalidatePathGeometryRequested(object sender, EventArgs e)
{
OnPropertyChanged(nameof(Data));
}
void OnTransformPropertyChanged(object sender, PropertyChangedEventArgs args)
{
if (args.PropertyName == Transform.ValueProperty.PropertyName)
{
OnPropertyChanged(nameof(RenderTransform));
}
}
// TODO this should move to a remapped mapper
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (propertyName == DataProperty.PropertyName)
{
Handler?.UpdateValue(nameof(IShapeView.Shape));
}
}
public override PathF GetPath()
{
var path = new PathF();
if (Data != null)
Data.AppendPath(path);
return path;
}
}
}