|
|
@ -72,7 +72,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml |
|
|
|
|
|
|
|
|
|
|
|
_xamlObject.Name = newName; |
|
|
|
_xamlObject.Name = newName; |
|
|
|
|
|
|
|
|
|
|
|
//FixReferencesOnNameChange(oldName, Name);
|
|
|
|
FixDesignItemReferencesOnNameChange(oldName, Name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override string Name { |
|
|
|
public override string Name { |
|
|
@ -89,14 +89,15 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void FixReferencesOnNameChange(string oldName, string newName) |
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Fixes {x:Reference and {Binding ElementName to this Element in XamlDocument
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="oldName"></param>
|
|
|
|
|
|
|
|
/// <param name="newName"></param>
|
|
|
|
|
|
|
|
public void FixDesignItemReferencesOnNameChange(string oldName, string newName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var root = this.Parent; |
|
|
|
var root = GetRootXamlObject(this.XamlObject); |
|
|
|
while (root.Parent != null) |
|
|
|
var references = GetAllChildXamlObjects(root).Where(x => x.ElementType == typeof(Reference) && Equals(x.FindOrCreateProperty("Name").ValueOnInstance, oldName)); |
|
|
|
root = root.Parent; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var references = GetAllChildDesignItems(((XamlDesignItem)root).XamlObject).Where(x => x.ElementType == typeof(Reference) && Equals(x.FindOrCreateProperty("Name").ValueOnInstance, oldName)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var designItem in references) |
|
|
|
foreach (var designItem in references) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var property = designItem.FindOrCreateProperty("Name"); |
|
|
|
var property = designItem.FindOrCreateProperty("Name"); |
|
|
@ -105,8 +106,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml |
|
|
|
property.PropertyValue = propertyValue; |
|
|
|
property.PropertyValue = propertyValue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var bindings = GetAllChildDesignItems(((XamlDesignItem)root).XamlObject).Where(x => x.ElementType == typeof(Binding) && Equals(x.FindOrCreateProperty("ElementName").ValueOnInstance, oldName)); |
|
|
|
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) |
|
|
|
foreach (var designItem in bindings) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var property = designItem.FindOrCreateProperty("ElementName"); |
|
|
|
var property = designItem.FindOrCreateProperty("ElementName"); |
|
|
@ -116,44 +117,44 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private IEnumerable<XamlObject> GetAllChildDesignItems(XamlObject item) |
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Find's the Root XamlObject (real Root, or Root Object in Namescope)
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="item"></param>
|
|
|
|
|
|
|
|
/// <param name="onlyFromSameNamescope"></param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
private XamlObject GetRootXamlObject(XamlObject item, bool onlyFromSameNamescope = false) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//if (item.ContentProperty != null)
|
|
|
|
var root = item; |
|
|
|
//{
|
|
|
|
while (root.ParentObject != null) |
|
|
|
// if (item.ContentProperty.Value != null)
|
|
|
|
{ |
|
|
|
// {
|
|
|
|
if (onlyFromSameNamescope && NameScopeHelper.GetNameScopeFromObject(root) != NameScopeHelper.GetNameScopeFromObject(root.ParentObject)) |
|
|
|
// yield return item.ContentProperty.Value;
|
|
|
|
break; |
|
|
|
|
|
|
|
root = root.ParentObject; |
|
|
|
// foreach (var i in GetAllChildDesignItems(item.ContentProperty.Value))
|
|
|
|
} |
|
|
|
// {
|
|
|
|
|
|
|
|
// yield return i;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (item.ContentProperty.IsCollection)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// foreach (var collectionElement in item.ContentProperty.CollectionElements)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// yield return collectionElement;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// foreach (var i in GetAllChildDesignItems(collectionElement))
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// yield return i;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return root; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Get's all Child XamlObject Instances
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="item"></param>
|
|
|
|
|
|
|
|
/// <param name="onlyFromSameNamescope"></param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
private IEnumerable<XamlObject> GetAllChildXamlObjects(XamlObject item, bool onlyFromSameNamescope = false) |
|
|
|
|
|
|
|
{ |
|
|
|
foreach (var prop in item.Properties) |
|
|
|
foreach (var prop in item.Properties) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (prop.PropertyValue as XamlObject != null) |
|
|
|
if (prop.PropertyValue as XamlObject != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
yield return prop.PropertyValue as XamlObject; |
|
|
|
if (!onlyFromSameNamescope || NameScopeHelper.GetNameScopeFromObject(item) == NameScopeHelper.GetNameScopeFromObject(prop.PropertyValue as XamlObject)) |
|
|
|
|
|
|
|
yield return prop.PropertyValue as XamlObject; |
|
|
|
|
|
|
|
|
|
|
|
foreach (var i in GetAllChildDesignItems(prop.PropertyValue as XamlObject)) |
|
|
|
foreach (var i in GetAllChildXamlObjects(prop.PropertyValue as XamlObject)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
yield return i; |
|
|
|
if (!onlyFromSameNamescope || NameScopeHelper.GetNameScopeFromObject(item) == NameScopeHelper.GetNameScopeFromObject(i)) |
|
|
|
|
|
|
|
yield return i; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -163,11 +164,13 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (collectionElement as XamlObject != null) |
|
|
|
if (collectionElement as XamlObject != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
yield return collectionElement as XamlObject; |
|
|
|
if (!onlyFromSameNamescope || NameScopeHelper.GetNameScopeFromObject(item) == NameScopeHelper.GetNameScopeFromObject(collectionElement as XamlObject)) |
|
|
|
|
|
|
|
yield return collectionElement as XamlObject; |
|
|
|
|
|
|
|
|
|
|
|
foreach (var i in GetAllChildDesignItems(collectionElement as XamlObject)) |
|
|
|
foreach (var i in GetAllChildXamlObjects(collectionElement as XamlObject)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
yield return i; |
|
|
|
if (!onlyFromSameNamescope || NameScopeHelper.GetNameScopeFromObject(item) == NameScopeHelper.GetNameScopeFromObject(i)) |
|
|
|
|
|
|
|
yield return i; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|