protected override Task OnToolDeactivateAsync(bool hasMapViewChanged) { // if we have a valid view model if (_attributeVM != null) { // free the embeddable control resources _attributeVM.InspectorView = null; _attributeVM.InspectorViewModel.Dispose(); } _attributeVM = null; return(base.OnToolDeactivateAsync(hasMapViewChanged)); }
protected override async Task OnToolActivateAsync(bool active) { // get the Precincts feature layer in the active map _pointLayer = ActiveMapView.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>(). Where(lyr => lyr.Name == "Police Stations").FirstOrDefault(); if (_pointLayer == null) { return; } // build the attribute dictionaries _attributesValid = new Dictionary <string, bool>(); _attributes = new Dictionary <string, object>(); // get the embedded control if (_attributeVM == null) { _attributeVM = this.EmbeddableControl as AttributeControlViewModel; } // these are the fields that we will collect values from the user var fieldNames = new List <string>() { "Precinct", "Address" }; // set up the inspector var inspector = new Inspector(); foreach (var fieldName in fieldNames) { // add the attribute ArcGIS.Desktop.Editing.Attributes.Attribute attr = await inspector.AddAttributeAsync(_pointLayer, fieldName, false); // set the validity to true _attributesValid.Add(fieldName, true); // add some validation - in this example we will make each field mandatory attr.AddValidate(() => { var errors = new List <ArcGIS.Desktop.Editing.Attributes.Attribute.ValidationError>(); if (string.IsNullOrWhiteSpace(attr.CurrentValue.ToString())) { // add an error errors.Add(ArcGIS.Desktop.Editing.Attributes.Attribute.ValidationError.Create("Value is mandatory", ArcGIS.Desktop.Editing.Attributes.Severity.High)); // set the validity to false _attributesValid[fieldName] = false; } else { // store the value if (!_attributes.ContainsKey(fieldName)) { _attributes.Add(fieldName, attr.CurrentValue); } else { _attributes[fieldName] = attr.CurrentValue; } // set the validity to true _attributesValid[fieldName] = true; } return(errors); }); } // create the embedded control and assign the view/viewmodel pair var tuple = inspector.CreateEmbeddableControl(); _attributeVM.InspectorViewModel = tuple.Item1; _attributeVM.InspectorView = tuple.Item2; }