diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ArrangeDirection.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ArrangeDirection.cs
new file mode 100644
index 0000000000..095d1c1f1b
--- /dev/null
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ArrangeDirection.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ICSharpCode.WpfDesign.Designer
+{
+ public enum ArrangeDirection
+ {
+ Top,
+ VerticalMiddle,
+ Bottom,
+ Left,
+ HorizontalMiddle,
+ Right,
+ }
+}
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml
new file mode 100644
index 0000000000..14b9e3597e
--- /dev/null
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml.cs
new file mode 100644
index 0000000000..9a1130ab54
--- /dev/null
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml.cs
@@ -0,0 +1,78 @@
+// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this
+// software and associated documentation files (the "Software"), to deal in the Software
+// without restriction, including without limitation the rights to use, copy, modify, merge,
+// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
+// to whom the Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all copies or
+// substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using ICSharpCode.WpfDesign.PropertyGrid;
+using ICSharpCode.WpfDesign.Designer.Xaml;
+
+namespace ICSharpCode.WpfDesign.Designer.Extensions
+{
+ public partial class ArrangeItemsContextMenu
+ {
+ private DesignItem designItem;
+
+ public ArrangeItemsContextMenu(DesignItem designItem)
+ {
+ this.designItem = designItem;
+
+ InitializeComponent();
+ }
+
+ void Click_ArrangeLeft(object sender, System.Windows.RoutedEventArgs e)
+ {
+ ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Left);
+ }
+
+ void Click_ArrangeHorizontalCentered(object sender, System.Windows.RoutedEventArgs e)
+ {
+ ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.HorizontalMiddle);
+ }
+
+ void Click_ArrangeRight(object sender, System.Windows.RoutedEventArgs e)
+ {
+ ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Right);
+ }
+
+ void Click_ArrangeTop(object sender, System.Windows.RoutedEventArgs e)
+ {
+ ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Top);
+ }
+
+ void Click_ArrangeVerticalCentered(object sender, System.Windows.RoutedEventArgs e)
+ {
+ ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.VerticalMiddle);
+ }
+
+ void Click_ArrangeBottom(object sender, System.Windows.RoutedEventArgs e)
+ {
+ ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Bottom);
+ }
+ }
+}
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenuExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenuExtension.cs
new file mode 100644
index 0000000000..582ad8f628
--- /dev/null
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenuExtension.cs
@@ -0,0 +1,58 @@
+// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this
+// software and associated documentation files (the "Software"), to deal in the Software
+// without restriction, including without limitation the rights to use, copy, modify, merge,
+// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
+// to whom the Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all copies or
+// substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+using System.Windows.Shapes;
+
+using ICSharpCode.WpfDesign.Adorners;
+using ICSharpCode.WpfDesign.Extensions;
+using ICSharpCode.WpfDesign.Designer;
+
+namespace ICSharpCode.WpfDesign.Designer.Extensions
+{
+ ///
+ ///
+ ///
+ [ExtensionServer(typeof(PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer))]
+ [ExtensionFor(typeof(UIElement))]
+ [Extension(Order = 30)]
+ public class ArrangeItemsContextMenuExtension : SelectionAdornerProvider
+ {
+ DesignPanel panel;
+ ContextMenu contextMenu;
+
+ protected override void OnInitialized()
+ {
+ base.OnInitialized();
+
+ contextMenu = new ArrangeItemsContextMenu(ExtendedItem);
+ panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
+ panel.AddContextMenu(contextMenu);
+ }
+
+ protected override void OnRemove()
+ {
+ panel.RemoveContextMenu(contextMenu);
+
+ base.OnRemove();
+ }
+ }
+}
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandleMultipleItems.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandleMultipleItems.cs
index 12a2505b3d..b5a915b2cd 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandleMultipleItems.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandleMultipleItems.cs
@@ -66,8 +66,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
minX = minX < relativeLocation.X ? minX : relativeLocation.X;
minY = minY < relativeLocation.Y ? minY : relativeLocation.Y;
- maxX = maxX > relativeLocation.X + ((FrameworkElement)this.ExtendedItem.View).ActualWidth ? maxX : relativeLocation.X + ((FrameworkElement)this.ExtendedItem.View).ActualWidth;
- maxY = maxY > relativeLocation.Y + ((FrameworkElement)this.ExtendedItem.View).ActualHeight ? maxY : relativeLocation.Y + ((FrameworkElement)this.ExtendedItem.View).ActualHeight;
+ maxX = maxX > relativeLocation.X + ((FrameworkElement)di.View).ActualWidth ? maxX : relativeLocation.X + ((FrameworkElement)di.View).ActualWidth;
+ maxY = maxY > relativeLocation.Y + ((FrameworkElement)di.View).ActualHeight ? maxY : relativeLocation.Y + ((FrameworkElement)di.View).ActualHeight;
}
Rectangle rect2 = new Rectangle() {
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml
similarity index 68%
rename from src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml
rename to src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml
index d6c69df71b..b39b39aae4 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml
@@ -1,8 +1,12 @@
-
-
+
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml.cs
similarity index 94%
rename from src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml.cs
rename to src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml.cs
index e616350d12..2e1fc583db 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml.cs
@@ -34,11 +34,11 @@ using ICSharpCode.WpfDesign.Designer.Xaml;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
- public partial class RightClickMultipleItemsContextMenu
- {
+ public partial class WrapItemsContextMenu
+ {
private DesignItem designItem;
- public RightClickMultipleItemsContextMenu(DesignItem designItem)
+ public WrapItemsContextMenu(DesignItem designItem)
{
this.designItem = designItem;
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenuExtension.cs
similarity index 92%
rename from src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs
rename to src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenuExtension.cs
index 11f7fcec88..8d7c0dd0db 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenuExtension.cs
@@ -33,7 +33,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
///
[ExtensionServer(typeof(PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer))]
[ExtensionFor(typeof(UIElement))]
- public class RightClickMultipleItemsContextMenuExtension : SelectionAdornerProvider
+ [Extension(Order = 50)]
+ public class WrapItemsContextMenuExtension : SelectionAdornerProvider
{
DesignPanel panel;
ContextMenu contextMenu;
@@ -42,7 +43,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{
base.OnInitialized();
- contextMenu = new RightClickMultipleItemsContextMenu(ExtendedItem);
+ contextMenu = new WrapItemsContextMenu(ExtendedItem);
panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
panel.AddContextMenu(contextMenu);
}
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/grid.png b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/grid.png
new file mode 100644
index 0000000000..2eb69a4e43
Binary files /dev/null and b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/grid.png differ
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
index 8e690d1b24..cc21ccfac4 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
@@ -229,8 +229,113 @@ namespace ICSharpCode.WpfDesign.Designer
public DesignItem DesignItem { get; set; }
}
-
- public static void WrapItemsNewContainer(IEnumerable items, Type containerType)
+
+ private static ItemPos GetItemPos(DesignItem designItem)
+ {
+ var itemPos = new ItemPos() {DesignItem = designItem};
+
+ if (designItem.Parent.Component is Canvas)
+ {
+ var canvas = designItem.Parent.View as Canvas;
+
+ if (designItem.Properties.GetAttachedProperty(Canvas.RightProperty) != null &&
+ designItem.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet)
+ {
+ itemPos.HorizontalAlignment = HorizontalAlignment.Right;
+ itemPos.Xmax = canvas.ActualWidth -
+ (double) designItem.Properties.GetAttachedProperty(Canvas.RightProperty).ValueOnInstance;
+ itemPos.Xmin = itemPos.Xmax - ((FrameworkElement) designItem.View).ActualWidth;
+ }
+ else if (designItem.Properties.GetAttachedProperty(Canvas.LeftProperty) != null &&
+ designItem.Properties.GetAttachedProperty(Canvas.LeftProperty).IsSet)
+ {
+ itemPos.HorizontalAlignment = HorizontalAlignment.Left;
+ itemPos.Xmin =
+ (double) designItem.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance;
+ itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth;
+ }
+ else
+ {
+ itemPos.HorizontalAlignment = HorizontalAlignment.Left;
+ itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth;
+ }
+
+ if (designItem.Properties.GetAttachedProperty(Canvas.BottomProperty) != null &&
+ designItem.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet)
+ {
+ itemPos.VerticalAlignment = VerticalAlignment.Bottom;
+ itemPos.Ymax = canvas.ActualHeight -
+ (double)
+ designItem.Properties.GetAttachedProperty(Canvas.BottomProperty).ValueOnInstance;
+ itemPos.Ymin = itemPos.Ymax - ((FrameworkElement) designItem.View).ActualHeight;
+ }
+ else if (designItem.Properties.GetAttachedProperty(Canvas.TopProperty) != null &&
+ designItem.Properties.GetAttachedProperty(Canvas.TopProperty).IsSet)
+ {
+ itemPos.VerticalAlignment = VerticalAlignment.Top;
+ itemPos.Ymin =
+ (double) designItem.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance;
+ itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight;
+ }
+ else
+ {
+ itemPos.VerticalAlignment = VerticalAlignment.Top;
+ itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight;
+ }
+ }
+ else if (designItem.Parent.Component is Grid)
+ {
+ var grid = designItem.Parent.View as Grid;
+
+ if (
+ (HorizontalAlignment)
+ designItem.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance ==
+ HorizontalAlignment.Right)
+ {
+ itemPos.HorizontalAlignment = HorizontalAlignment.Right;
+ itemPos.Xmax = grid.ActualWidth -
+ ((Thickness)
+ designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance)
+ .Right;
+ itemPos.Xmin = itemPos.Xmax - ((FrameworkElement) designItem.View).ActualWidth;
+ }
+ else
+ {
+ itemPos.HorizontalAlignment = HorizontalAlignment.Left;
+ itemPos.Xmin =
+ ((Thickness) designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance)
+ .Left;
+ itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth;
+ }
+
+ if (
+ (VerticalAlignment)
+ designItem.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance ==
+ VerticalAlignment.Bottom)
+ {
+ itemPos.VerticalAlignment = VerticalAlignment.Bottom;
+ itemPos.Ymax = grid.ActualHeight -
+ ((Thickness)
+ designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance)
+ .Bottom;
+ itemPos.Ymin = itemPos.Ymax - ((FrameworkElement) designItem.View).ActualHeight;
+ }
+ else
+ {
+ itemPos.VerticalAlignment = VerticalAlignment.Top;
+ itemPos.Ymin =
+ ((Thickness) designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance)
+ .Top;
+ itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight;
+ }
+
+
+ }
+
+ return itemPos;
+ }
+
+ public static void WrapItemsNewContainer(IEnumerable items, Type containerType)
{
var collection = items;
@@ -248,68 +353,14 @@ namespace ICSharpCode.WpfDesign.Designer
List itemList = new List();
foreach (var item in collection) {
-
- var itemPos = new ItemPos(){ DesignItem = item };
- itemList.Add(itemPos);
+ itemList.Add(GetItemPos(item));
if (oldContainer.Component is Canvas) {
- var canvas = oldContainer.View as Canvas;
-
- if (item.Properties.GetAttachedProperty(Canvas.RightProperty) != null && item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) {
- itemPos.HorizontalAlignment = HorizontalAlignment.Right;
- itemPos.Xmax = canvas.ActualWidth - (double)item.Properties.GetAttachedProperty(Canvas.RightProperty).ValueOnInstance;
- itemPos.Xmin = itemPos.Xmax - ((FrameworkElement)item.View).ActualWidth;
- }
- else if (item.Properties.GetAttachedProperty(Canvas.LeftProperty) != null && item.Properties.GetAttachedProperty(Canvas.LeftProperty).IsSet) {
- itemPos.HorizontalAlignment = HorizontalAlignment.Left;
- itemPos.Xmin = (double)item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance;
- itemPos.Xmax = itemPos.Xmin + ((FrameworkElement)item.View).ActualWidth;
- } else {
- itemPos.HorizontalAlignment = HorizontalAlignment.Left;
- itemPos.Xmax = itemPos.Xmin + ((FrameworkElement)item.View).ActualWidth;
- }
-
- if (item.Properties.GetAttachedProperty(Canvas.BottomProperty) != null && item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) {
- itemPos.VerticalAlignment = VerticalAlignment.Bottom;
- itemPos.Ymax = canvas.ActualHeight - (double)item.Properties.GetAttachedProperty(Canvas.BottomProperty).ValueOnInstance;
- itemPos.Ymin = itemPos.Ymax - ((FrameworkElement)item.View).ActualHeight;
- }
- else if (item.Properties.GetAttachedProperty(Canvas.TopProperty) != null && item.Properties.GetAttachedProperty(Canvas.TopProperty).IsSet) {
- itemPos.VerticalAlignment = VerticalAlignment.Top;
- itemPos.Ymin = (double)item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance;
- itemPos.Ymax = itemPos.Ymin + ((FrameworkElement)item.View).ActualHeight;
- } else {
- itemPos.VerticalAlignment = VerticalAlignment.Top;
- itemPos.Ymax = itemPos.Ymin + ((FrameworkElement)item.View).ActualHeight;
- }
-
item.Properties.GetAttachedProperty(Canvas.RightProperty).Reset();
item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset();
item.Properties.GetAttachedProperty(Canvas.TopProperty).Reset();
item.Properties.GetAttachedProperty(Canvas.BottomProperty).Reset();
} else if (oldContainer.Component is Grid) {
- var grid = oldContainer.View as Grid;
-
- if ((HorizontalAlignment)item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance == HorizontalAlignment.Right) {
- itemPos.HorizontalAlignment = HorizontalAlignment.Right;
- itemPos.Xmax = grid.ActualWidth - ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Right;
- itemPos.Xmin = itemPos.Xmax - ((FrameworkElement)item.View).ActualWidth;
- } else {
- itemPos.HorizontalAlignment = HorizontalAlignment.Left;
- itemPos.Xmin = ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Left;
- itemPos.Xmax = itemPos.Xmin + ((FrameworkElement)item.View).ActualWidth;
- }
-
- if ((VerticalAlignment)item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance == VerticalAlignment.Bottom) {
- itemPos.VerticalAlignment = VerticalAlignment.Bottom;
- itemPos.Ymax = grid.ActualHeight - ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Bottom;
- itemPos.Ymin = itemPos.Ymax - ((FrameworkElement)item.View).ActualHeight;
- } else {
- itemPos.VerticalAlignment = VerticalAlignment.Top;
- itemPos.Ymin = ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Top;
- itemPos.Ymax = itemPos.Ymin + ((FrameworkElement)item.View).ActualHeight;
- }
-
item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).Reset();
item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).Reset();
item.Properties.GetProperty(FrameworkElement.MarginProperty).Reset();
@@ -380,5 +431,167 @@ namespace ICSharpCode.WpfDesign.Designer
_context.Services.Selection.SetSelectedComponents(new []{ newPanel });
}
- }
+
+ public static void ArrangeItems(IEnumerable items, ArrangeDirection arrangeDirection)
+ {
+ var collection = items;
+
+ var _context = collection.First().Context as XamlDesignContext;
+
+ var container = collection.First().Parent;
+
+ if (collection.Any(x => x.Parent != container))
+ return;
+
+ var changeGroup = container.OpenGroup("Arrange Elements");
+
+ List itemList = new List();
+ foreach (var item in collection)
+ {
+ itemList.Add(GetItemPos(item));
+ }
+
+ var xmin = itemList.Min(x => x.Xmin);
+ var xmax = itemList.Max(x => x.Xmax);
+ var mpos = (xmax - xmin) / 2 + xmin;
+ var ymin = itemList.Min(x => x.Ymin);
+ var ymax = itemList.Max(x => x.Ymax);
+ var ympos = (ymax - ymin) / 2 + ymin;
+
+ foreach (var item in collection)
+ {
+ switch (arrangeDirection)
+ {
+ case ArrangeDirection.Left:
+ {
+ if (container.Component is Canvas)
+ {
+ if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet)
+ {
+ item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(xmin);
+ }
+ else
+ {
+ var pos = (double)((Panel)item.Parent.Component).ActualWidth - (xmin + (double) ((FrameworkElement) item.Component).ActualWidth);
+ item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos);
+ }
+ }
+ else if (container.Component is Grid)
+ {
+
+ }
+ }
+ break;
+ case ArrangeDirection.HorizontalMiddle:
+ {
+ if (container.Component is Canvas)
+ {
+ if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet)
+ {
+ item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(mpos - (((FrameworkElement)item.Component).ActualWidth) / 2);
+ }
+ else
+ {
+ var pp = mpos - (((FrameworkElement) item.Component).ActualWidth)/2;
+ var pos = (double)((Panel)item.Parent.Component).ActualWidth - pp - (((FrameworkElement)item.Component).ActualWidth);
+ item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos);
+ }
+ }
+ else if (container.Component is Grid)
+ {
+
+ }
+ }
+ break;
+ case ArrangeDirection.Right:
+ {
+ if (container.Component is Canvas)
+ {
+ if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet)
+ {
+ var pos = xmax - (double)((FrameworkElement)item.Component).ActualWidth;
+ item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(pos);
+ }
+ else
+ {
+ var pos = (double)((Panel)item.Parent.Component).ActualWidth - xmax;
+ item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos);
+ }
+ }
+ else if (container.Component is Grid)
+ {
+
+ }
+ }
+ break;
+ case ArrangeDirection.Top:
+ {
+ if (container.Component is Canvas)
+ {
+ if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet)
+ {
+ item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ymin);
+ }
+ else
+ {
+ var pos = (double)((Panel)item.Parent.Component).ActualHeight - (ymin + (double)((FrameworkElement)item.Component).ActualHeight);
+ item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos);
+ }
+ }
+ else if (container.Component is Grid)
+ {
+
+ }
+ }
+ break;
+ case ArrangeDirection.VerticalMiddle:
+ {
+ if (container.Component is Canvas)
+ {
+ if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet)
+ {
+ item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ympos - (((FrameworkElement)item.Component).ActualHeight) / 2);
+ }
+ else
+ {
+ var pp = mpos - (((FrameworkElement)item.Component).ActualHeight) / 2;
+ var pos = (double)((Panel)item.Parent.Component).ActualHeight - pp - (((FrameworkElement)item.Component).ActualHeight);
+ item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos);
+ }
+ }
+ else if (container.Component is Grid)
+ {
+
+ }
+ }
+ break;
+ case ArrangeDirection.Bottom:
+ {
+ if (container.Component is Canvas)
+ {
+ if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet)
+ {
+ var pos = ymax - (double)((FrameworkElement)item.Component).ActualHeight;
+ item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(pos);
+ }
+ else
+ {
+ var pos = (double)((Panel)item.Parent.Component).ActualHeight - ymax;
+ item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos);
+ }
+ }
+ else if (container.Component is Grid)
+ {
+
+ }
+ }
+ break;
+ }
+ }
+ changeGroup.Commit();
+
+ //_context.Services.Selection.SetSelectedComponents(null);
+ //_context.Services.Selection.SetSelectedComponents(items.ToList());
+ }
+ }
}
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Translations.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Translations.cs
index eca0f9ac3d..6944e334c1 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Translations.cs
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Translations.cs
@@ -92,6 +92,52 @@ namespace ICSharpCode.WpfDesign.Designer
}
}
-
+ public virtual string ArrangeLeft
+ {
+ get
+ {
+ return "Arrange Left";
+ }
+ }
+
+ public virtual string ArrangeHorizontalMiddle
+ {
+ get
+ {
+ return "Horizontal centered";
+ }
+ }
+
+ public virtual string ArrangeRight
+ {
+ get
+ {
+ return "Arrange Right";
+ }
+ }
+
+ public virtual string ArrangeTop
+ {
+ get
+ {
+ return "Arrange Top";
+ }
+ }
+
+ public virtual string ArrangeVerticalMiddle
+ {
+ get
+ {
+ return "Vertical centered";
+ }
+ }
+
+ public virtual string ArrangeBottom
+ {
+ get
+ {
+ return "Arrange Bottom";
+ }
+ }
}
}
diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
index 70a098f32d..55d01fddc2 100644
--- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
+++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
@@ -83,6 +83,7 @@
Configuration\GlobalAssemblyInfo.cs
+
@@ -95,10 +96,14 @@
+
+
+ ArrangeItemsContextMenu.xaml
+
-
-
- RightClickMultipleItemsContextMenu.xaml
+
+
+ WrapItemsContextMenu.xaml
@@ -279,7 +284,12 @@
Designer
-
+
+ Designer
+
+
+ Designer
+
@@ -425,4 +435,7 @@
+
+
+
\ No newline at end of file