/// <summary>
        /// Delete an XML node
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ClearItem(Object sender, RoutedEventArgs e)
        {
            string           message = Internal.Metadata.Properties.Resources.MSGBOX_DELETE_MSG;
            string           caption = Internal.Metadata.Properties.Resources.MSGBOX_DELETE_CAPTION;
            MessageBoxButton button  = MessageBoxButton.OKCancel;
            MessageBoxImage  icon    = MessageBoxImage.Question;

            // show dialog
            MessageBoxResult result = ArcGIS.Desktop.Internal.Framework.DialogManager.ShowMessageBox(message, caption, button, icon);

            switch (result)
            {
            case MessageBoxResult.Cancel:
                return;
            }

            // get tag
            string tag = Utils.GetStringTag(sender);

            // get the data context and apply fill to each element
            IEnumerable <XmlNode> data = Utils.GetXmlDataContext(Utils.GetDataContext(sender));

            if (null != data)
            {
                foreach (XmlNode node in data)
                {
                    // remove the element from the tree
                    node.InnerXml = String.Empty;
                    MetadataEditorViewModel.UpdateDataContext(this as DependencyObject);
                    break;
                }
            }
        }
        /// <summary>
        /// Add an XML Node by Tag
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void AddRecordByTag(Object sender, RoutedEventArgs e)
        {
            string tag = Utils.GetStringTag(sender);

            ArcGIS.Desktop.Metadata.Editor.Utils.FillXml(this, false, true, tag);
            MetadataEditorViewModel.UpdateDataContext(this as DependencyObject);
        }
 public EditorPage()
 {
     this.Loaded += delegate
     {
         MetadataEditorViewModel vm = Utils.GetMetadataEditorViewModel(this) as MetadataEditorViewModel;
         if (vm != null)
         {
             vm.IsLoadingPage = false;
         }
     };
 }
        /// <summary>
        /// Delete an XML node
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void DeleteItem(Object sender, RoutedEventArgs e)
        {
            string           message = Internal.Metadata.Properties.Resources.MSGBOX_DELETE_MSG;
            string           caption = Internal.Metadata.Properties.Resources.MSGBOX_DELETE_CAPTION;
            MessageBoxButton button  = MessageBoxButton.OKCancel;
            MessageBoxImage  icon    = MessageBoxImage.Question;

            // show dialog
            MessageBoxResult result = ArcGIS.Desktop.Internal.Framework.DialogManager.ShowMessageBox(message, caption, button, icon);

            switch (result)
            {
            case MessageBoxResult.Cancel:
                return;
            }

            // Mark metadata dirty first
            MetadataEditorViewModel vm = Utils.GetMetadataEditorViewModel(this) as MetadataEditorViewModel;

            if (vm != null)
            {
                vm.Metadata_NodeChanged(null, null);
            }

            // get tag
            string tag = Utils.GetStringTag(sender);

            // get the data context and apply fill to each element
            IEnumerable <XmlNode> data = Utils.GetXmlDataContext(Utils.GetDataContext(sender));

            if (null != data)
            {
                foreach (XmlNode node in data)
                {
                    if ("deleteParent".Equals(tag))
                    {
                        // get the root control first, b/c the data context
                        // to which the current control is bound
                        // will be deleted,
                        // then updateDataContext will fail, b/c
                        // the root MetadataEditorControl can't be found in the tree anymore
                        var mec = Utils.GetMetadataEditorControl(this);

                        XmlNode parentNode  = node.ParentNode;
                        XmlNode deletedNode = parentNode.ParentNode.RemoveChild(parentNode);
                        if (null == deletedNode || deletedNode != parentNode)
                        {
                            throw new MetadataException("Error deleting node!");
                        }

                        MetadataEditorViewModel.UpdateDataContext(mec);
                        break;;
                    }
                    else
                    {
                        // remove the element from the tree
                        XmlNode deletedNode = node.ParentNode.RemoveChild(node);
                        if (null == deletedNode || deletedNode != node)
                        {
                            throw new Exception("Error deleting node!");
                        }

                        MetadataEditorViewModel.UpdateDataContext(this as DependencyObject);
                        break;
                    }
                }
            }
        }
 /// <summary>
 /// Add XML Node
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void AddRecord(Object sender, RoutedEventArgs e)
 {
     ArcGIS.Desktop.Metadata.Editor.Utils.FillXml(this, false, false);
     MetadataEditorViewModel.UpdateDataContext(this as DependencyObject);
 }