/// <summary> /// Initializes a new instance of the <see cref="SensusUI.ScriptRunnersPage"/> class. /// </summary> /// <param name="probe">Probe to display.</param> public ScriptRunnersPage(ScriptProbe probe) { _probe = probe; Title = "Scripts"; _scriptRunnersList = new ListView(); _scriptRunnersList.ItemTemplate = new DataTemplate(typeof(TextCell)); _scriptRunnersList.ItemTemplate.SetBinding(TextCell.TextProperty, "Name"); _scriptRunnersList.ItemTapped += async (o, e) => { if (_scriptRunnersList.SelectedItem == null) return; ScriptRunner selectedScriptRunner = _scriptRunnersList.SelectedItem as ScriptRunner; string selectedAction = await DisplayActionSheet(selectedScriptRunner.Name, "Cancel", null, "Edit", "Delete"); if (selectedAction == "Edit") { ScriptRunnerPage scriptRunnerPage = new ScriptRunnerPage(selectedScriptRunner); scriptRunnerPage.Disappearing += (oo, ee) => { Bind(); }; await Navigation.PushAsync(scriptRunnerPage); } else if (selectedAction == "Delete") { if (await DisplayAlert("Delete " + selectedScriptRunner.Name + "?", "This action cannot be undone.", "Delete", "Cancel")) { selectedScriptRunner.Stop(); _probe.ScriptRunners.Remove(selectedScriptRunner); _scriptRunnersList.SelectedItem = null; // reset manually since it's not done automatically } } }; ToolbarItems.Add(new ToolbarItem(null, "plus.png", () => { _probe.ScriptRunners.Add(new ScriptRunner("New Script", _probe)); })); Bind(); Content = _scriptRunnersList; }
public ScriptRunner(string name, ScriptProbe probe) : this() { _name = name; _probe = probe; }