From 24f4bb8ed5183eb7250bd20206249321bb0a3859 Mon Sep 17 00:00:00 2001
From: jkuehner <jochen.kuehner@kardex.com>
Date: Tue, 13 Jan 2015 11:44:56 +0100
Subject: [PATCH 1/4] Fix Menu should always be black

---
 .../WpfDesign.Designer/Project/Controls/ControlStyles.xaml      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml
index 000e7bba3b..b84b82e06d 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml
@@ -91,7 +91,7 @@
 						<Line HorizontalAlignment="Left" VerticalAlignment="Top" Stroke="{TemplateBinding Foreground}"  StrokeThickness="1" StrokeDashArray="2 2" X1="3.5" Y1="3.5" X2="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=RelativeToPoint.X}" Y2="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=RelativeToPoint.Y}" Visibility="{Binding Path=RelativeToPoint, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static Converters:CollapsedWhenNull.Instance}}" />
 						<Rectangle HorizontalAlignment="Left" VerticalAlignment="Top" Width="7" Height="7"  Name="thumbRectangle" SnapsToDevicePixels="True" Stroke="{TemplateBinding Foreground}" Fill="White" RadiusX="1.414" RadiusY="1.414" />
 						<Ellipse HorizontalAlignment="Left" VerticalAlignment="Top" Width="7" Height="7"  Name="thumbElipse" Stroke="{TemplateBinding Foreground}" SnapsToDevicePixels="True" Fill="White" Visibility="Collapsed" />
-						<Menu Height="15" HorizontalAlignment="Left" Margin="0,-19,-19,0" VerticalAlignment="Top" Width="15" BorderThickness="0" Background="Transparent" Visibility="{Binding Path=OperationMenu, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static Converters:CollapsedWhenNull.Instance}}" >
+						<Menu Foreground="Black" Height="15" HorizontalAlignment="Left" Margin="0,-19,-19,0" VerticalAlignment="Top" Width="15" BorderThickness="0" Background="Transparent" Visibility="{Binding Path=OperationMenu, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static Converters:CollapsedWhenNull.Instance}}" >
 							<MenuItem Height="15" Width="15" Padding="0" Background="Transparent" BorderThickness="1" ItemsSource="{TemplateBinding OperationMenu}">
 								<MenuItem.Header>
 									<Path Data="M3.5,5.5 L11.5,5.5 L7.5,11 z" Fill="Black" Stroke="Gray" StrokeThickness="1" />

From 2ede4f41056e8f3ae3b3c2883ca92b80403e7d23 Mon Sep 17 00:00:00 2001
From: jkuehner <jochen.kuehner@kardex.com>
Date: Wed, 14 Jan 2015 15:18:09 +0100
Subject: [PATCH 2/4] For Perf. Reasons don't use Exception

---
 .../Project/CollectionSupport.cs              | 23 +++++++++++++------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs
index 01b71be2f6..98d3e71cf6 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs
@@ -105,13 +105,22 @@ namespace ICSharpCode.WpfDesign.XamlDom
 			/// <summary>
 		/// Adds a value at the specified index in the collection.
 		/// </summary>
-		public static void Insert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index)
+		public static bool Insert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index)
 		{
-			collectionType.InvokeMember(
-				"Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance,
-				null, collectionInstance,
-				new object[] { index, newElement.GetValueFor(null) },
-				CultureInfo.InvariantCulture);
+			var mth = collectionType.GetMethod("Insert", BindingFlags.Public | BindingFlags.Instance,
+			                         null, CallingConventions.Any, new Type[]{ typeof(int), typeof(object) }, null);
+			
+			if (mth != null) {
+				collectionType.InvokeMember(
+					"Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance,
+					null, collectionInstance,
+					new object[] { index, newElement.GetValueFor(null) },
+					CultureInfo.InvariantCulture);
+				
+				return true;
+			}
+			
+			return false;
 		}
 		
 		/// <summary>
@@ -121,7 +130,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
 		internal static bool TryInsert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index)
 		{
 			try {
-				Insert(collectionType, collectionInstance, newElement, index);
+				return Insert(collectionType, collectionInstance, newElement, index);
 			} catch (MissingMethodException) {
 				return false;
 			}

From 5aaced89af270e28416694c69631f49a38f8d978 Mon Sep 17 00:00:00 2001
From: jkuehner <jochen.kuehner@kardex.com>
Date: Wed, 14 Jan 2015 15:40:25 +0100
Subject: [PATCH 3/4] Fix adding two times the same string in the Designer:

This does not work before:
                            var addItem = page.designSurface.DesignContext.Services.Component.RegisterComponentForDesigner(se.Value);

                            addItem.Key = se.Key;
                            d.Properties["Hardware"].CollectionElements.Add(addItem);

maybe we also need to change for Value Types!
---
 .../WpfDesign.Designer/Project/Xaml/XamlComponentService.cs    | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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 e51ab53ce2..9998929502 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs
@@ -89,7 +89,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
 			}
 			
 			XamlDesignItem item = new XamlDesignItem(_context.Document.CreateObject(component), _context);
-			_sites.Add(component, item);
+			if (!(component is string))
+				_sites.Add(component, item);
 			if (ComponentRegistered != null) {
 				ComponentRegistered(this, new DesignItemEventArgs(item));
 			}

From 47a67fe2d73fe1caeeb4c390eb933c4ced21eaa4 Mon Sep 17 00:00:00 2001
From: jkuehner <jochen.kuehner@kardex.com>
Date: Wed, 14 Jan 2015 16:38:25 +0100
Subject: [PATCH 4/4] Last fix was not correct -> We don't know the Type of the
 Insert Object

---
 .../Project/CollectionSupport.cs              | 24 +++++++++----------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs
index 98d3e71cf6..42f73d18d8 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs
@@ -21,6 +21,7 @@ using System.Diagnostics;
 using System.Collections;
 using System.ComponentModel;
 using System.Globalization;
+using System.Linq;
 using System.Reflection;
 using System.Windows;
 using System.Windows.Documents;
@@ -39,11 +40,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
 		public static bool IsCollectionType(Type type)
 		{
 			return type != typeof(LineBreak) && (
-                   typeof(IList).IsAssignableFrom(type)
+				typeof(IList).IsAssignableFrom(type)
 				|| type.IsArray
 				|| typeof(IAddChild).IsAssignableFrom(type)
 				|| typeof(IDictionary).IsAssignableFrom(type));
-		}		
+		}
 
 		/// <summary>
 		/// Gets if the collection type <paramref name="col"/> can accepts items of type
@@ -85,12 +86,12 @@ namespace ICSharpCode.WpfDesign.XamlDom
 			} else if (collectionInstance is IDictionary) {
 				object val = newElement.GetValueFor(null);
 				object key = newElement is XamlObject ? ((XamlObject)newElement).GetXamlAttribute("Key") : null;
-                if (key == null || key == "")
-                {
-                    if (val is Style)
-                        key = ((Style)val).TargetType;
-                }
-                if (key == null || (key as string) == "")
+				if (key == null || key == "")
+				{
+					if (val is Style)
+						key = ((Style)val).TargetType;
+				}
+				if (key == null || (key as string) == "")
 					key = val;
 				((IDictionary)collectionInstance).Add(key, val);
 			} else {
@@ -102,15 +103,14 @@ namespace ICSharpCode.WpfDesign.XamlDom
 			}
 		}
 		
-			/// <summary>
+		/// <summary>
 		/// Adds a value at the specified index in the collection.
 		/// </summary>
 		public static bool Insert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index)
 		{
-			var mth = collectionType.GetMethod("Insert", BindingFlags.Public | BindingFlags.Instance,
-			                         null, CallingConventions.Any, new Type[]{ typeof(int), typeof(object) }, null);
+			var hasInsert = collectionType.GetMethods().Any(x => x.Name == "Insert");
 			
-			if (mth != null) {
+			if (hasInsert) {
 				collectionType.InvokeMember(
 					"Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance,
 					null, collectionInstance,