-
Notifications
You must be signed in to change notification settings - Fork 520
/
SaveMapPage.xaml.cs
90 lines (75 loc) · 3.22 KB
/
SaveMapPage.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
namespace ArcGIS.Samples.AuthorMap
{
public partial class SaveMapPage : ContentPage
{
// Raise an event so the listener can access input values when the form has been completed
public event EventHandler<SaveMapEventArgs> OnSaveClicked;
public SaveMapPage()
{
InitializeComponent();
}
// If updating an existing map item, show the existing item info and disable changing info
public void ShowForUpdate(string title, string description, string[] tags)
{
// Item title
MapTitleEntry.Text = title;
MapTitleEntry.IsEnabled = false;
// Item description
MapDescriptionEntry.Text = description;
MapDescriptionEntry.IsEnabled = false;
// Item tags
MapTagsEntry.Text = string.Join(",", tags);
MapTagsEntry.IsEnabled = false;
// Show 'Update' rather than 'Save' for button text
SaveMapButton.Text = "Update";
}
// A click handler for the save map button
private void SaveButtonClicked(object sender, EventArgs e)
{
try
{
// Get information for the new portal item
string title = MapTitleEntry.Text;
string description = MapDescriptionEntry.Text;
string[] tags = MapTagsEntry.Text.Split(',');
// Make sure all required info was entered
if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(description) || tags.Length == 0)
{
throw new Exception("Please enter a title, description, and some tags to describe the map.");
}
// Create a new OnSaveMapEventArgs object to store the information entered by the user
SaveMapEventArgs mapSavedArgs = new SaveMapEventArgs(title, description, tags);
// Raise the OnSaveClicked event so the main activity can handle the event and save the map
OnSaveClicked?.Invoke(this, mapSavedArgs);
// Close the dialog
Application.Current.MainPage.Navigation.PopAsync();
}
catch (Exception ex)
{
// Show the exception message (dialog will stay open so user can try again)
Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
}
}
private void CancelButtonClicked(object sender, EventArgs e)
{
// If the user cancels, just navigate back to the previous page
Application.Current.MainPage.Navigation.PopAsync();
}
}
// Custom EventArgs class for containing portal item properties when saving a map
public class SaveMapEventArgs : EventArgs
{
// Portal item title
public string MapTitle { get; set; }
// Portal item description
public string MapDescription { get; set; }
// Portal item tags
public string[] Tags { get; set; }
public SaveMapEventArgs(string title, string description, string[] tags) : base()
{
MapTitle = title;
MapDescription = description;
Tags = tags;
}
}
}