|
|
|
@ -229,8 +229,113 @@ namespace ICSharpCode.WpfDesign.Designer
@@ -229,8 +229,113 @@ namespace ICSharpCode.WpfDesign.Designer
|
|
|
|
|
|
|
|
|
|
public DesignItem DesignItem { get; set; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void WrapItemsNewContainer(IEnumerable<DesignItem> 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<DesignItem> items, Type containerType) |
|
|
|
|
{ |
|
|
|
|
var collection = items; |
|
|
|
|
|
|
|
|
@ -248,68 +353,14 @@ namespace ICSharpCode.WpfDesign.Designer
@@ -248,68 +353,14 @@ namespace ICSharpCode.WpfDesign.Designer
|
|
|
|
|
List<ItemPos> itemList = new List<ItemPos>(); |
|
|
|
|
|
|
|
|
|
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
@@ -380,5 +431,167 @@ namespace ICSharpCode.WpfDesign.Designer
|
|
|
|
|
|
|
|
|
|
_context.Services.Selection.SetSelectedComponents(new []{ newPanel }); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void ArrangeItems(IEnumerable<DesignItem> 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<ItemPos> itemList = new List<ItemPos>(); |
|
|
|
|
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());
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|