/// <summary>
        /// Prepares the content for the embeddable control when the tool is activated.
        /// </summary>
        /// <param name="hasMapViewChanged"></param>
        /// <returns></returns>
        protected override Task OnToolActivateAsync(bool hasMapViewChanged)
        {
            // if reference to the view model exists, create one
            if (_attributeVM == null)
            {
                _attributeVM = this.EmbeddableControl as AttributeControlViewModel;
            }


            // initiate the following code to execute on the MCT
            QueuedTask.Run(() =>
            {
                // get the current selection for the active map
                var selectionInMap = ActiveMapView.Map.GetSelection();

                // get the first point layer from the map
                var pointLayer = ActiveMapView.Map.GetLayersAsFlattenedList().
                OfType<FeatureLayer>().
                Where(lyr => lyr.ShapeType == ArcGIS.Core.CIM.esriGeometryType.esriGeometryPoint).
                FirstOrDefault();

                if (pointLayer != null)
                {
                    // if the point layer contains selected features
                    if (selectionInMap.ContainsKey(pointLayer))
                    {
                        // get a list of the selected point features 
                        var selectionDictionary = new Dictionary<MapMember, List<long>>();
                        selectionDictionary.Add(pointLayer as MapMember, selectionInMap[pointLayer]);
                        // and store it in the view model, this property populates the tree view
                        _attributeVM.SelectedMapFeatures = selectionDictionary;

                        // load the first selected point feature
                        _attributeVM.AttributeInspector.Load(pointLayer, selectionInMap[pointLayer][0]);
                    }

                    // subsribe to the PropertyChanged event for the string attributes
                    foreach (ArcGIS.Desktop.Editing.Attributes.Attribute featureAttribute in _attributeVM.AttributeInspector)
                    {
                        if (featureAttribute.FieldType == FieldType.String)
                        {
                           featureAttribute.PropertyChanged += FeatureAttributeChanged;
                        }
                    }
                }
            });

            return Task.FromResult(true);
        }
        private void treeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            _vm = this.DataContext as AttributeControlViewModel;

            var layerTreeView = sender as TreeView;
            
            var selectedFeature = layerTreeView.Items.CurrentItem;
            var selectionLayer = ((KeyValuePair < MapMember, List< long >> )selectedFeature).Key;

            if (layerTreeView.SelectedItem.GetType() == typeof(System.Int64))
            {
                var selectedOID = Convert.ToInt64(layerTreeView.SelectedItem);

                _vm.AttributeInspector?.LoadAsync(selectionLayer, selectedOID);
            }
            else
            {
                _vm.AttributeInspector.ClearAsync();
            }
        }
 public AttributeControlView()
 {
     InitializeComponent();
     _vm = this.DataContext as AttributeControlViewModel;
 }
        /// <summary>
        /// Clears resources when the tool is deactivated.
        /// </summary>
        /// <param name="hasMapViewChanged"></param>
        /// <returns></returns>
        protected override Task OnToolDeactivateAsync(bool hasMapViewChanged)
        {
            // if we have a valid view model
            if (_attributeVM != null)
            {
                // if there is a valid instance for the attribute inspector
                // unsubscribe from the events for the string attributes
                if (_attributeVM.AttributeInspector != null)
                {
                    foreach (ArcGIS.Desktop.Editing.Attributes.Attribute featureAttribute in _attributeVM.AttributeInspector)
                    {
                        if (featureAttribute.FieldType == FieldType.String)
                        {
                            featureAttribute.PropertyChanged -= FeatureAttributeChanged;
                        }
                    }
                }

                // free the embeddable control resources
                _attributeVM.InspectorView = null;
                _attributeVM.InspectorViewModel.Dispose();

                _attributeVM = null;
            }

            return Task.FromResult(true);
        }