@ -20,8 +20,11 @@
//#define EventHandlerDebugging
//#define EventHandlerDebugging
using System ;
using System ;
using System.Collections.Generic ;
using System.Diagnostics ;
using System.Diagnostics ;
using System.Linq ;
using System.Windows ;
using System.Windows ;
using System.Windows.Data ;
using ICSharpCode.WpfDesign.XamlDom ;
using ICSharpCode.WpfDesign.XamlDom ;
using ICSharpCode.WpfDesign.Designer.Services ;
using ICSharpCode.WpfDesign.Designer.Services ;
using System.Windows.Markup ;
using System.Windows.Markup ;
@ -65,7 +68,11 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
void SetNameInternal ( string newName )
void SetNameInternal ( string newName )
{
{
var oldName = Name ;
_ xamlObject . Name = newName ;
_ xamlObject . Name = newName ;
//FixReferencesOnNameChange(oldName, Name);
}
}
public override string Name {
public override string Name {
@ -75,8 +82,97 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
if ( undoService ! = null )
if ( undoService ! = null )
undoService . Execute ( new SetNameAction ( this , value ) ) ;
undoService . Execute ( new SetNameAction ( this , value ) ) ;
else
else
{
SetNameInternal ( value ) ;
SetNameInternal ( value ) ;
}
}
}
}
public void FixReferencesOnNameChange ( string oldName , string newName )
{
var root = this . Parent ;
while ( root . Parent ! = null )
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 )
{
var property = designItem . FindOrCreateProperty ( "Name" ) ;
var propertyValue = designItem . OwnerDocument . CreatePropertyValue ( newName , property ) ;
this . ComponentService . RegisterXamlComponentRecursive ( propertyValue as XamlObject ) ;
property . PropertyValue = propertyValue ;
}
var bindings = GetAllChildDesignItems ( ( ( XamlDesignItem ) root ) . XamlObject ) . 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 ;
}
}
private IEnumerable < XamlObject > GetAllChildDesignItems ( XamlObject item )
{
//if (item.ContentProperty != null)
//{
// if (item.ContentProperty.Value != null)
// {
// yield return item.ContentProperty.Value;
// 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;
// }
// }
// }
//}
foreach ( var prop in item . Properties )
{
if ( prop . PropertyValue as XamlObject ! = null )
{
yield return prop . PropertyValue as XamlObject ;
foreach ( var i in GetAllChildDesignItems ( prop . PropertyValue as XamlObject ) )
{
yield return i ;
}
}
if ( prop . IsCollection )
{
foreach ( var collectionElement in prop . CollectionElements )
{
if ( collectionElement as XamlObject ! = null )
{
yield return collectionElement as XamlObject ;
foreach ( var i in GetAllChildDesignItems ( collectionElement as XamlObject ) )
{
yield return i ;
}
}
}
}
}
}
}
public override string Key {
public override string Key {