Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 195d403

Browse files
author
tbulle
committed
Changes to make reverse cloning possible
1 parent ada43bb commit 195d403

6 files changed

Lines changed: 28 additions & 8 deletions

File tree

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void designPanel_DragLeave(object sender, DragEventArgs e)
152152
protected virtual DesignItem CreateItem(DesignContext context)
153153
{
154154
object newInstance = context.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory(componentType, null);
155-
DesignItem item = context.Services.Component.RegisterComponentForDesigner(newInstance);
155+
DesignItem item = context.Services.Component.RegisterComponentForDesigner(newInstance, componentType);
156156
changeGroup = item.OpenGroup("Drop Control");
157157
context.Services.ExtensionManager.ApplyDefaultInitializers(item);
158158
return item;

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
using System.Runtime.CompilerServices;
2222
using System.Windows.Markup;
2323
using System.Windows;
24-
24+
using ICSharpCode.WpfDesign.Extensions;
2525
using ICSharpCode.WpfDesign.XamlDom;
2626

2727
namespace ICSharpCode.WpfDesign.Designer.Xaml
@@ -68,15 +68,18 @@ public DesignItem GetDesignItem(object component)
6868
return site;
6969
}
7070

71-
public DesignItem RegisterComponentForDesigner(object component)
71+
public DesignItem RegisterComponentForDesigner(object component, Type basetype = null)
7272
{
7373
if (component == null) {
7474
component = new NullExtension();
7575
} else if (component is Type) {
7676
component = new TypeExtension((Type)component);
7777
}
78-
79-
XamlDesignItem item = new XamlDesignItem(_context.Document.CreateObject(component), _context);
78+
79+
object baseobject = basetype != null && component.GetType()!=basetype ? CustomInstanceFactory.CreateObjectInstance(basetype, null) : null;
80+
XamlObject xamlobj = _context.Document.CreateObject(component, baseobject);
81+
82+
XamlDesignItem item = new XamlDesignItem(xamlobj, _context);
8083
_sites.Add(component, item);
8184
if (ComponentRegistered != null) {
8285
ComponentRegistered(this, new DesignItemEventArgs(item));

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,14 @@ internal void ParseComplete(XamlObject rootElement)
158158
/// <summary>
159159
/// Create an XamlObject from the instance.
160160
/// </summary>
161-
public XamlObject CreateObject(object instance)
161+
public XamlObject CreateObject(object instance, object baseobject=null)
162162
{
163-
return (XamlObject)CreatePropertyValue(instance, null);
163+
object obj = instance;
164+
if (baseobject != null && instance.GetType() != baseobject.GetType())
165+
obj = baseobject;
166+
XamlObject xamlobj = (XamlObject)CreatePropertyValue(obj, null);
167+
xamlobj.Instance = instance;
168+
return xamlobj;
164169
}
165170

166171
/// <summary>

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ public XamlDocument OwnerDocument {
287287
/// </summary>
288288
public object Instance {
289289
get { return instance; }
290+
internal set { instance = value; }
290291
}
291292

292293
/// <summary>

src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/CustomInstanceFactory.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,18 @@ protected CustomInstanceFactory()
4848
/// <summary>
4949
/// Creates an instance of the specified type, passing the specified arguments to its constructor.
5050
/// </summary>
51+
/// <param name="type"></param>
52+
/// <param name="arguments"></param>
53+
/// <returns></returns>
5154
public virtual object CreateInstance(Type type, params object[] arguments)
55+
{
56+
return CreateObjectInstance(type, arguments);
57+
}
58+
59+
/// <summary>
60+
/// Creates an instance of the specified type, passing the specified arguments to its constructor.
61+
/// </summary>
62+
public static object CreateObjectInstance(Type type, params object[] arguments)
5263
{
5364
var instance = Activator.CreateInstance(type, arguments);
5465
var uiElement = instance as UIElement;

src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public interface IComponentService
122122
DesignItem GetDesignItem(object component);
123123

124124
/// <summary>Registers a component for usage in the designer.</summary>
125-
DesignItem RegisterComponentForDesigner(object component);
125+
DesignItem RegisterComponentForDesigner(object component, Type basetype=null);
126126

127127
/// <summary>Event raised whenever a component is registered</summary>
128128
event EventHandler<DesignItemEventArgs> ComponentRegistered;

0 commit comments

Comments
 (0)