-
Notifications
You must be signed in to change notification settings - Fork 88
/
EditorToolbar.xaml.cs
103 lines (88 loc) · 4.13 KB
/
EditorToolbar.xaml.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
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI;
using Esri.ArcGISRuntime.UI.Editing;
using System.Windows;
using System.Windows.Controls;
namespace EditorDemo
{
public partial class EditorToolbar : UserControl
{
private readonly EditorToolbarController _controller = new EditorToolbarController();
public EditorToolbar()
{
InitializeComponent();
this.DataContext = _controller;
_controller.PropertyChanged += Controller_PropertyChanged;
_controller.EditingCompleted += (s,e) => EditingCompleted?.Invoke(this, new EditingCompletedEventArgs(e));
_controller.EditingCancelled += (s, e) => EditingCancelled?.Invoke(this, new EventArgs());
}
public class EditingCompletedEventArgs : EventArgs
{
public EditingCompletedEventArgs(Geometry geometry)
{
Geometry = geometry;
}
public Geometry Geometry { get; }
}
public event EventHandler<EditingCompletedEventArgs>? EditingCompleted;
public event EventHandler? EditingCancelled;
private void Controller_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(EditorToolbarController.GeometryEditor))
{
GeometryEditor = _controller.GeometryEditor;
}
}
internal static readonly DependencyPropertyKey GeometryEditorPropertyKey =
DependencyProperty.RegisterReadOnly(
name: nameof(GeometryEditor),
propertyType: typeof(GeometryEditor),
ownerType: typeof(EditorToolbar),
typeMetadata: new FrameworkPropertyMetadata());
/// <summary>
/// Gets the active geometry editor. Bind this back to the MapView
/// </summary>
public GeometryEditor? GeometryEditor
{
get => (GeometryEditor)GetValue(GeometryEditorPropertyKey.DependencyProperty);
private set => SetValue(GeometryEditorPropertyKey, value);
}
/// <summary>
/// The GeoElement that should be edited
/// </summary>
public GeoElement? GeoElement
{
get { return (GeoElement)GetValue(GeoElementProperty); }
set { SetValue(GeoElementProperty, value); }
}
public static readonly DependencyProperty GeoElementProperty =
DependencyProperty.Register(nameof(GeoElement), typeof(GeoElement), typeof(EditorToolbar), new PropertyMetadata(null, (s, e) => ((EditorToolbar)s).OnGeoElementPropertyChanged(e.OldValue as GeoElement, e.NewValue as GeoElement)));
private void OnGeoElementPropertyChanged(GeoElement? oldElement, GeoElement? newElement)
{
_controller.GeoElement = newElement;
}
/// <summary>
/// Reference to the MapView's GraphicsOverlays
/// </summary>
public GraphicsOverlayCollection GraphicsOverlays
{
get { return (GraphicsOverlayCollection)GetValue(GraphicsOverlaysProperty); }
set { SetValue(GraphicsOverlaysProperty, value); }
}
public static readonly DependencyProperty GraphicsOverlaysProperty =
DependencyProperty.Register(nameof(GraphicsOverlays), typeof(GraphicsOverlayCollection), typeof(EditorToolbar), new PropertyMetadata(null, (s, e) => ((EditorToolbar)s).OnGraphicsOverlayPropertyChanged(e.OldValue as GraphicsOverlayCollection, e.NewValue as GraphicsOverlayCollection)));
private void OnGraphicsOverlayPropertyChanged(GraphicsOverlayCollection? oldOverlays, GraphicsOverlayCollection? newOverlays)
{
_controller.GraphicsOverlays = newOverlays;
}
/// <summary>
/// Returns true if this geoelement supports geometry editing.
/// </summary>
/// <param name="geoElement"></param>
/// <returns></returns>
public static bool CanEditGeometry(GeoElement? geoElement) => EditorToolbarController.CanEditGeometry(geoElement);
}
}