diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs index 81fa1cddd3..5fbc9df801 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs @@ -105,7 +105,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml } if (_context.RootItem != null && !string.IsNullOrEmpty(site.Name)) { - var nameScope = NameScopeHelper.GetNameScopeFromObject(_context.RootItem.Component); + var nameScope = NameScopeHelper.GetNameScopeFromObject(((XamlDesignItem)_context.RootItem).XamlObject); if (nameScope != null) { // The object will be a part of the RootItem namescope, remove local namescope if set diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs index e70e3c1a20..05ac5433e7 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs @@ -20,6 +20,7 @@ using System; using System.Diagnostics; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Windows; using ICSharpCode.WpfDesign.XamlDom; using ICSharpCode.WpfDesign.Designer.Services; using System.Collections.Specialized; @@ -179,6 +180,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml if (CollectionChanged != null) CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index)); + + NameScopeHelper.NameChanged(item.XamlObject, item.Name, null); } void InsertInternal(int index, XamlDesignItem item) @@ -187,6 +190,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml if (CollectionChanged != null) CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index)); + + NameScopeHelper.NameChanged(item.XamlObject, null, item.Name); } sealed class InsertAction : ITransactionItem diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/NameScopeHelper.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/NameScopeHelper.cs index 689cd684db..a6ca2769b2 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/NameScopeHelper.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/NameScopeHelper.cs @@ -34,11 +34,11 @@ namespace ICSharpCode.WpfDesign.XamlDom /// The object where the name was changed. /// The old name. /// The new name. - internal static void NameChanged(XamlObject namedObject, string oldName, string newName) + public static void NameChanged(XamlObject namedObject, string oldName, string newName) { var obj = namedObject; while (obj != null) { - var nameScope = GetNameScopeFromObject(obj.Instance); + var nameScope = GetNameScopeFromObject(obj); if (nameScope != null) { if (oldName != null) { try { @@ -69,15 +69,27 @@ namespace ICSharpCode.WpfDesign.XamlDom /// /// The object to get the XAML namescope for. /// A XAML namescope, as an instance. - public static INameScope GetNameScopeFromObject(object obj) + public static INameScope GetNameScopeFromObject(XamlObject obj) { - var nameScope = obj as INameScope; - if (nameScope == null) { - var depObj = obj as DependencyObject; - if (depObj != null) - nameScope = NameScope.GetNameScope(depObj); + INameScope nameScope = null; + + while (obj != null) + { + nameScope = obj.Instance as INameScope; + if (nameScope == null) + { + var xamlObj = obj.ParentObject != null ? obj.ParentObject : obj; + var depObj = xamlObj.Instance as DependencyObject; + if (depObj != null) + nameScope = NameScope.GetNameScope(depObj); + + if (nameScope != null) + break; + } + + obj = obj.ParentObject; } - + return nameScope; } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs index 7d06a90ae6..0afa53096f 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs @@ -195,7 +195,7 @@ namespace ICSharpCode.WpfDesign.XamlDom var xamlObj = this.XamlObject; while (xamlObj != null) { - ns = NameScopeHelper.GetNameScopeFromObject(xamlObj.Instance); + ns = NameScopeHelper.GetNameScopeFromObject(xamlObj); if (ns != null) { var obj = ns.FindName(name);