Browse Source

Xaml Namescope fixes

pull/593/head
jkuehner 11 years ago
parent
commit
b4f59a361e
  1. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs
  2. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs
  3. 30
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/NameScopeHelper.cs
  4. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs

@ -105,7 +105,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -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

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs

@ -20,6 +20,7 @@ using System; @@ -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 @@ -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 @@ -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

30
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/NameScopeHelper.cs

@ -34,11 +34,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -34,11 +34,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// <param name="namedObject">The object where the name was changed.</param>
/// <param name="oldName">The old name.</param>
/// <param name="newName">The new name.</param>
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 @@ -69,15 +69,27 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// </summary>
/// <param name="obj">The object to get the XAML namescope for.</param>
/// <returns>A XAML namescope, as an <see cref="INameScope"/> instance.</returns>
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;
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs

@ -195,7 +195,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -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);

Loading…
Cancel
Save