ICSharpCode.WpfDesign.Designer.Xaml.XamlDesignItem.FixDesignItemReferencesOnNameChange C# (CSharp) Method

FixDesignItemReferencesOnNameChange() public method

Fixes {x:Reference and {Binding ElementName to this Element in XamlDocument
public FixDesignItemReferencesOnNameChange ( string oldName, string newName ) : void
oldName string
newName string
return void
        public void FixDesignItemReferencesOnNameChange(string oldName, string newName)
        {
            if (!string.IsNullOrEmpty(oldName) && !string.IsNullOrEmpty(newName)) {
                var root = GetRootXamlObject(this.XamlObject);
                var references = GetAllChildXamlObjects(root).Where(x => x.ElementType == typeof(Reference) && Equals(x.FindOrCreateProperty("Name").ValueOnInstance, oldName));
                foreach (var designItem in references)
                {
                    var property = designItem.FindOrCreateProperty("Name");
                    var propertyValue = designItem.OwnerDocument.CreatePropertyValue(newName, property);
                    this.ComponentService.RegisterXamlComponentRecursive(propertyValue as XamlObject);
                    property.PropertyValue = propertyValue;
                }

                root = GetRootXamlObject(this.XamlObject, true);
                var bindings = GetAllChildXamlObjects(root, true).Where(x => x.ElementType == typeof(Binding) && Equals(x.FindOrCreateProperty("ElementName").ValueOnInstance, oldName));
                foreach (var designItem in bindings)
                {
                    var property = designItem.FindOrCreateProperty("ElementName");
                    var propertyValue = designItem.OwnerDocument.CreatePropertyValue(newName, property);
                    this.ComponentService.RegisterXamlComponentRecursive(propertyValue as XamlObject);
                    property.PropertyValue = propertyValue;
                }
            }
        }