|
|
@ -123,45 +123,45 @@ namespace ICSharpCode.WpfDesign.Designer |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
var fixedDoc = new FixedDocument(); |
|
|
|
var fixedDoc = new FixedDocument(); |
|
|
|
var pageContent = new PageContent(); |
|
|
|
var pageContent = new PageContent(); |
|
|
|
var fixedPage = new FixedPage(); |
|
|
|
var fixedPage = new FixedPage(); |
|
|
|
fixedPage.Children.Add(element); |
|
|
|
fixedPage.Children.Add(element); |
|
|
|
(pageContent as IAddChild).AddChild(fixedPage); |
|
|
|
(pageContent as IAddChild).AddChild(fixedPage); |
|
|
|
fixedDoc.Pages.Add(pageContent); |
|
|
|
fixedDoc.Pages.Add(pageContent); |
|
|
|
|
|
|
|
|
|
|
|
var f = new XpsSerializerFactory(); |
|
|
|
var f = new XpsSerializerFactory(); |
|
|
|
var w = f.CreateSerializerWriter(new MemoryStream()); |
|
|
|
var w = f.CreateSerializerWriter(new MemoryStream()); |
|
|
|
w.Write(fixedDoc); |
|
|
|
w.Write(fixedDoc); |
|
|
|
|
|
|
|
|
|
|
|
fixedPage.Children.Remove(element); |
|
|
|
fixedPage.Children.Remove(element); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
catch (Exception) |
|
|
|
{ } |
|
|
|
{ } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
internal static Size GetDefaultSize(DesignItem createdItem) |
|
|
|
internal static Size GetDefaultSize(DesignItem createdItem) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var defS = Metadata.GetDefaultSize(createdItem.ComponentType, false); |
|
|
|
var defS = Metadata.GetDefaultSize(createdItem.ComponentType, false); |
|
|
|
if (defS != null) |
|
|
|
if (defS != null) |
|
|
|
return defS.Value; |
|
|
|
return defS.Value; |
|
|
|
|
|
|
|
|
|
|
|
CreateVisualTree(createdItem.View); |
|
|
|
CreateVisualTree(createdItem.View); |
|
|
|
|
|
|
|
|
|
|
|
var s = createdItem.View.DesiredSize; |
|
|
|
var s = createdItem.View.DesiredSize; |
|
|
|
|
|
|
|
|
|
|
|
var newS = Metadata.GetDefaultSize(createdItem.ComponentType, true); |
|
|
|
var newS = Metadata.GetDefaultSize(createdItem.ComponentType, true); |
|
|
|
|
|
|
|
|
|
|
|
if (newS.HasValue) |
|
|
|
if (newS.HasValue) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!(s.Width > 5) && newS.Value.Width > 0) |
|
|
|
if (!(s.Width > 5) && newS.Value.Width > 0) |
|
|
|
s.Width = newS.Value.Width; |
|
|
|
s.Width = newS.Value.Width; |
|
|
|
|
|
|
|
|
|
|
|
if (!(s.Height > 5) && newS.Value.Height > 0) |
|
|
|
if (!(s.Height > 5) && newS.Value.Height > 0) |
|
|
|
s.Height = newS.Value.Height; |
|
|
|
s.Height = newS.Value.Height; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (double.IsNaN(s.Width) && GetWidth(createdItem.View) > 0) { |
|
|
|
if (double.IsNaN(s.Width) && GetWidth(createdItem.View) > 0) { |
|
|
|
s.Width = GetWidth(createdItem.View); |
|
|
|
s.Width = GetWidth(createdItem.View); |
|
|
|
} |
|
|
|
} |
|
|
|
if (double.IsNaN(s.Height) && GetWidth(createdItem.View) > 0) { |
|
|
|
if (double.IsNaN(s.Height) && GetWidth(createdItem.View) > 0) { |
|
|
@ -192,16 +192,16 @@ namespace ICSharpCode.WpfDesign.Designer |
|
|
|
public static void Resize(DesignItem item, double newWidth, double newHeight) |
|
|
|
public static void Resize(DesignItem item, double newWidth, double newHeight) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (newWidth != GetWidth(item.View)) { |
|
|
|
if (newWidth != GetWidth(item.View)) { |
|
|
|
if(double.IsNaN(newWidth)) |
|
|
|
if(double.IsNaN(newWidth)) |
|
|
|
item.Properties.GetProperty(FrameworkElement.WidthProperty).Reset(); |
|
|
|
item.Properties.GetProperty(FrameworkElement.WidthProperty).Reset(); |
|
|
|
else |
|
|
|
else |
|
|
|
item.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(newWidth); |
|
|
|
item.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(newWidth); |
|
|
|
} |
|
|
|
} |
|
|
|
if (newHeight != GetHeight(item.View)) { |
|
|
|
if (newHeight != GetHeight(item.View)) { |
|
|
|
if (double.IsNaN(newHeight)) |
|
|
|
if (double.IsNaN(newHeight)) |
|
|
|
item.Properties.GetProperty(FrameworkElement.HeightProperty).Reset(); |
|
|
|
item.Properties.GetProperty(FrameworkElement.HeightProperty).Reset(); |
|
|
|
else |
|
|
|
else |
|
|
|
item.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(newHeight); |
|
|
|
item.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(newHeight); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -223,120 +223,120 @@ namespace ICSharpCode.WpfDesign.Designer |
|
|
|
public DesignItem DesignItem { get; set; } |
|
|
|
public DesignItem DesignItem { get; set; } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static ItemPos GetItemPos(IPlacementBehavior placementBehavior, DesignItem designItem) |
|
|
|
private static ItemPos GetItemPos(IPlacementBehavior placementBehavior, DesignItem designItem) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var itemPos = new ItemPos() {DesignItem = designItem}; |
|
|
|
var itemPos = new ItemPos() {DesignItem = designItem}; |
|
|
|
|
|
|
|
|
|
|
|
var pos = placementBehavior.GetPosition(null, designItem); |
|
|
|
var pos = placementBehavior.GetPosition(null, designItem); |
|
|
|
itemPos.Xmin = pos.X; |
|
|
|
itemPos.Xmin = pos.X; |
|
|
|
itemPos.Xmax = pos.X + pos.Width; |
|
|
|
itemPos.Xmax = pos.X + pos.Width; |
|
|
|
itemPos.Ymin = pos.Y; |
|
|
|
itemPos.Ymin = pos.Y; |
|
|
|
itemPos.Ymax = pos.Y + pos.Height; |
|
|
|
itemPos.Ymax = pos.Y + pos.Height; |
|
|
|
|
|
|
|
|
|
|
|
return itemPos; |
|
|
|
return itemPos; |
|
|
|
|
|
|
|
|
|
|
|
if (designItem.Parent.Component is Canvas) |
|
|
|
if (designItem.Parent.Component is Canvas) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var canvas = designItem.Parent.View as Canvas; |
|
|
|
var canvas = designItem.Parent.View as Canvas; |
|
|
|
|
|
|
|
|
|
|
|
if (designItem.Properties.GetAttachedProperty(Canvas.RightProperty) != null && |
|
|
|
if (designItem.Properties.GetAttachedProperty(Canvas.RightProperty) != null && |
|
|
|
designItem.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) |
|
|
|
designItem.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
itemPos.HorizontalAlignment = HorizontalAlignment.Right; |
|
|
|
itemPos.HorizontalAlignment = HorizontalAlignment.Right; |
|
|
|
itemPos.Xmax = canvas.ActualWidth - |
|
|
|
itemPos.Xmax = canvas.ActualWidth - |
|
|
|
(double) designItem.Properties.GetAttachedProperty(Canvas.RightProperty).ValueOnInstance; |
|
|
|
(double) designItem.Properties.GetAttachedProperty(Canvas.RightProperty).ValueOnInstance; |
|
|
|
itemPos.Xmin = itemPos.Xmax - ((FrameworkElement) designItem.View).ActualWidth; |
|
|
|
itemPos.Xmin = itemPos.Xmax - ((FrameworkElement) designItem.View).ActualWidth; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (designItem.Properties.GetAttachedProperty(Canvas.LeftProperty) != null && |
|
|
|
else if (designItem.Properties.GetAttachedProperty(Canvas.LeftProperty) != null && |
|
|
|
designItem.Properties.GetAttachedProperty(Canvas.LeftProperty).IsSet) |
|
|
|
designItem.Properties.GetAttachedProperty(Canvas.LeftProperty).IsSet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
itemPos.HorizontalAlignment = HorizontalAlignment.Left; |
|
|
|
itemPos.HorizontalAlignment = HorizontalAlignment.Left; |
|
|
|
itemPos.Xmin = |
|
|
|
itemPos.Xmin = |
|
|
|
(double) designItem.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance; |
|
|
|
(double) designItem.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance; |
|
|
|
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth; |
|
|
|
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
itemPos.HorizontalAlignment = HorizontalAlignment.Left; |
|
|
|
itemPos.HorizontalAlignment = HorizontalAlignment.Left; |
|
|
|
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth; |
|
|
|
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (designItem.Properties.GetAttachedProperty(Canvas.BottomProperty) != null && |
|
|
|
if (designItem.Properties.GetAttachedProperty(Canvas.BottomProperty) != null && |
|
|
|
designItem.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) |
|
|
|
designItem.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
itemPos.VerticalAlignment = VerticalAlignment.Bottom; |
|
|
|
itemPos.VerticalAlignment = VerticalAlignment.Bottom; |
|
|
|
itemPos.Ymax = canvas.ActualHeight - |
|
|
|
itemPos.Ymax = canvas.ActualHeight - |
|
|
|
(double) |
|
|
|
(double) |
|
|
|
designItem.Properties.GetAttachedProperty(Canvas.BottomProperty).ValueOnInstance; |
|
|
|
designItem.Properties.GetAttachedProperty(Canvas.BottomProperty).ValueOnInstance; |
|
|
|
itemPos.Ymin = itemPos.Ymax - ((FrameworkElement) designItem.View).ActualHeight; |
|
|
|
itemPos.Ymin = itemPos.Ymax - ((FrameworkElement) designItem.View).ActualHeight; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (designItem.Properties.GetAttachedProperty(Canvas.TopProperty) != null && |
|
|
|
else if (designItem.Properties.GetAttachedProperty(Canvas.TopProperty) != null && |
|
|
|
designItem.Properties.GetAttachedProperty(Canvas.TopProperty).IsSet) |
|
|
|
designItem.Properties.GetAttachedProperty(Canvas.TopProperty).IsSet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
itemPos.VerticalAlignment = VerticalAlignment.Top; |
|
|
|
itemPos.VerticalAlignment = VerticalAlignment.Top; |
|
|
|
itemPos.Ymin = |
|
|
|
itemPos.Ymin = |
|
|
|
(double) designItem.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance; |
|
|
|
(double) designItem.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance; |
|
|
|
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight; |
|
|
|
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
itemPos.VerticalAlignment = VerticalAlignment.Top; |
|
|
|
itemPos.VerticalAlignment = VerticalAlignment.Top; |
|
|
|
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight; |
|
|
|
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (designItem.Parent.Component is Grid) |
|
|
|
else if (designItem.Parent.Component is Grid) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var grid = designItem.Parent.View as Grid; |
|
|
|
var grid = designItem.Parent.View as Grid; |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
if ( |
|
|
|
(HorizontalAlignment) |
|
|
|
(HorizontalAlignment) |
|
|
|
designItem.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance == |
|
|
|
designItem.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance == |
|
|
|
HorizontalAlignment.Right) |
|
|
|
HorizontalAlignment.Right) |
|
|
|
{ |
|
|
|
{ |
|
|
|
itemPos.HorizontalAlignment = HorizontalAlignment.Right; |
|
|
|
itemPos.HorizontalAlignment = HorizontalAlignment.Right; |
|
|
|
itemPos.Xmax = grid.ActualWidth - |
|
|
|
itemPos.Xmax = grid.ActualWidth - |
|
|
|
((Thickness) |
|
|
|
((Thickness) |
|
|
|
designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance) |
|
|
|
designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance) |
|
|
|
.Right; |
|
|
|
.Right; |
|
|
|
itemPos.Xmin = itemPos.Xmax - ((FrameworkElement) designItem.View).ActualWidth; |
|
|
|
itemPos.Xmin = itemPos.Xmax - ((FrameworkElement) designItem.View).ActualWidth; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
itemPos.HorizontalAlignment = HorizontalAlignment.Left; |
|
|
|
itemPos.HorizontalAlignment = HorizontalAlignment.Left; |
|
|
|
itemPos.Xmin = |
|
|
|
itemPos.Xmin = |
|
|
|
((Thickness) designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance) |
|
|
|
((Thickness) designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance) |
|
|
|
.Left; |
|
|
|
.Left; |
|
|
|
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth; |
|
|
|
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
if ( |
|
|
|
(VerticalAlignment) |
|
|
|
(VerticalAlignment) |
|
|
|
designItem.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance == |
|
|
|
designItem.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance == |
|
|
|
VerticalAlignment.Bottom) |
|
|
|
VerticalAlignment.Bottom) |
|
|
|
{ |
|
|
|
{ |
|
|
|
itemPos.VerticalAlignment = VerticalAlignment.Bottom; |
|
|
|
itemPos.VerticalAlignment = VerticalAlignment.Bottom; |
|
|
|
itemPos.Ymax = grid.ActualHeight - |
|
|
|
itemPos.Ymax = grid.ActualHeight - |
|
|
|
((Thickness) |
|
|
|
((Thickness) |
|
|
|
designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance) |
|
|
|
designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance) |
|
|
|
.Bottom; |
|
|
|
.Bottom; |
|
|
|
itemPos.Ymin = itemPos.Ymax - ((FrameworkElement) designItem.View).ActualHeight; |
|
|
|
itemPos.Ymin = itemPos.Ymax - ((FrameworkElement) designItem.View).ActualHeight; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
itemPos.VerticalAlignment = VerticalAlignment.Top; |
|
|
|
itemPos.VerticalAlignment = VerticalAlignment.Top; |
|
|
|
itemPos.Ymin = |
|
|
|
itemPos.Ymin = |
|
|
|
((Thickness) designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance) |
|
|
|
((Thickness) designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance) |
|
|
|
.Top; |
|
|
|
.Top; |
|
|
|
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight; |
|
|
|
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return itemPos; |
|
|
|
return itemPos; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void WrapItemsNewContainer(IEnumerable<DesignItem> items, Type containerType) |
|
|
|
public static void WrapItemsNewContainer(IEnumerable<DesignItem> items, Type containerType) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var collection = items; |
|
|
|
var collection = items; |
|
|
|
|
|
|
|
|
|
|
@ -347,12 +347,12 @@ namespace ICSharpCode.WpfDesign.Designer |
|
|
|
if (collection.Any(x => x.Parent != container)) |
|
|
|
if (collection.Any(x => x.Parent != container)) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
//Change Code to use the Placment Operation!
|
|
|
|
//Change Code to use the Placment Operation!
|
|
|
|
var placement = container.Extensions.OfType<IPlacementBehavior>().FirstOrDefault(); |
|
|
|
var placement = container.Extensions.OfType<IPlacementBehavior>().FirstOrDefault(); |
|
|
|
if (placement == null) |
|
|
|
if (placement == null) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
var newInstance = Activator.CreateInstance(containerType); |
|
|
|
var newInstance = Activator.CreateInstance(containerType); |
|
|
|
DesignItem newPanel = _context.Services.Component.RegisterComponentForDesigner(newInstance); |
|
|
|
DesignItem newPanel = _context.Services.Component.RegisterComponentForDesigner(newInstance); |
|
|
|
var changeGroup = newPanel.OpenGroup("Wrap in Container"); |
|
|
|
var changeGroup = newPanel.OpenGroup("Wrap in Container"); |
|
|
|
|
|
|
|
|
|
|
@ -360,7 +360,7 @@ namespace ICSharpCode.WpfDesign.Designer |
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in collection) { |
|
|
|
foreach (var item in collection) { |
|
|
|
itemList.Add(GetItemPos(placement, item)); |
|
|
|
itemList.Add(GetItemPos(placement, item)); |
|
|
|
//var pos = placement.GetPosition(null, item);
|
|
|
|
//var pos = placement.GetPosition(null, item);
|
|
|
|
if (container.Component is Canvas) { |
|
|
|
if (container.Component is Canvas) { |
|
|
|
item.Properties.GetAttachedProperty(Canvas.RightProperty).Reset(); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.RightProperty).Reset(); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset(); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset(); |
|
|
@ -381,7 +381,7 @@ namespace ICSharpCode.WpfDesign.Designer |
|
|
|
var ymin = itemList.Min(x => x.Ymin); |
|
|
|
var ymin = itemList.Min(x => x.Ymin); |
|
|
|
var ymax = itemList.Max(x => x.Ymax); |
|
|
|
var ymax = itemList.Max(x => x.Ymax); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in itemList) { |
|
|
|
foreach (var item in itemList) { |
|
|
|
newPanel.ContentProperty.CollectionElements.Add(item.DesignItem); |
|
|
|
newPanel.ContentProperty.CollectionElements.Add(item.DesignItem); |
|
|
|
|
|
|
|
|
|
|
|
if (newPanel.Component is Canvas) { |
|
|
|
if (newPanel.Component is Canvas) { |
|
|
@ -418,184 +418,184 @@ namespace ICSharpCode.WpfDesign.Designer |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PlacementOperation operation = PlacementOperation.TryStartInsertNewComponents( |
|
|
|
PlacementOperation operation = PlacementOperation.TryStartInsertNewComponents( |
|
|
|
container, |
|
|
|
container, |
|
|
|
new[] { newPanel }, |
|
|
|
new[] { newPanel }, |
|
|
|
new[] { new Rect(xmin, ymin, xmax - xmin, ymax - ymin).Round() }, |
|
|
|
new[] { new Rect(xmin, ymin, xmax - xmin, ymax - ymin).Round() }, |
|
|
|
PlacementType.AddItem |
|
|
|
PlacementType.AddItem |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
operation.Commit(); |
|
|
|
operation.Commit(); |
|
|
|
|
|
|
|
|
|
|
|
changeGroup.Commit(); |
|
|
|
changeGroup.Commit(); |
|
|
|
|
|
|
|
|
|
|
|
_context.Services.Selection.SetSelectedComponents(new []{ newPanel }); |
|
|
|
_context.Services.Selection.SetSelectedComponents(new []{ newPanel }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void ArrangeItems(IEnumerable<DesignItem> items, ArrangeDirection arrangeDirection) |
|
|
|
public static void ArrangeItems(IEnumerable<DesignItem> items, ArrangeDirection arrangeDirection) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var collection = items; |
|
|
|
var collection = items; |
|
|
|
|
|
|
|
|
|
|
|
var _context = collection.First().Context as XamlDesignContext; |
|
|
|
var _context = collection.First().Context as XamlDesignContext; |
|
|
|
|
|
|
|
|
|
|
|
var container = collection.First().Parent; |
|
|
|
var container = collection.First().Parent; |
|
|
|
|
|
|
|
|
|
|
|
if (collection.Any(x => x.Parent != container)) |
|
|
|
if (collection.Any(x => x.Parent != container)) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
var placement = container.Extensions.OfType<IPlacementBehavior>().FirstOrDefault(); |
|
|
|
var placement = container.Extensions.OfType<IPlacementBehavior>().FirstOrDefault(); |
|
|
|
if (placement == null) |
|
|
|
if (placement == null) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
var changeGroup = container.OpenGroup("Arrange Elements"); |
|
|
|
var changeGroup = container.OpenGroup("Arrange Elements"); |
|
|
|
|
|
|
|
|
|
|
|
List<ItemPos> itemList = new List<ItemPos>(); |
|
|
|
List<ItemPos> itemList = new List<ItemPos>(); |
|
|
|
foreach (var item in collection) |
|
|
|
foreach (var item in collection) |
|
|
|
{ |
|
|
|
{ |
|
|
|
itemList.Add(GetItemPos(placement, item)); |
|
|
|
itemList.Add(GetItemPos(placement, item)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var xmin = itemList.Min(x => x.Xmin); |
|
|
|
var xmin = itemList.Min(x => x.Xmin); |
|
|
|
var xmax = itemList.Max(x => x.Xmax); |
|
|
|
var xmax = itemList.Max(x => x.Xmax); |
|
|
|
var mpos = (xmax - xmin) / 2 + xmin; |
|
|
|
var mpos = (xmax - xmin) / 2 + xmin; |
|
|
|
var ymin = itemList.Min(x => x.Ymin); |
|
|
|
var ymin = itemList.Min(x => x.Ymin); |
|
|
|
var ymax = itemList.Max(x => x.Ymax); |
|
|
|
var ymax = itemList.Max(x => x.Ymax); |
|
|
|
var ympos = (ymax - ymin) / 2 + ymin; |
|
|
|
var ympos = (ymax - ymin) / 2 + ymin; |
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in collection) |
|
|
|
foreach (var item in collection) |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch (arrangeDirection) |
|
|
|
switch (arrangeDirection) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case ArrangeDirection.Left: |
|
|
|
case ArrangeDirection.Left: |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (container.Component is Canvas) |
|
|
|
if (container.Component is Canvas) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) |
|
|
|
if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(xmin); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(xmin); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
var pos = (double)((Panel)item.Parent.Component).ActualWidth - (xmin + (double) ((FrameworkElement) item.Component).ActualWidth); |
|
|
|
var pos = (double)((Panel)item.Parent.Component).ActualWidth - (xmin + (double) ((FrameworkElement) item.Component).ActualWidth); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (container.Component is Grid) |
|
|
|
else if (container.Component is Grid) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case ArrangeDirection.HorizontalMiddle: |
|
|
|
case ArrangeDirection.HorizontalMiddle: |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (container.Component is Canvas) |
|
|
|
if (container.Component is Canvas) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) |
|
|
|
if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(mpos - (((FrameworkElement)item.Component).ActualWidth) / 2); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(mpos - (((FrameworkElement)item.Component).ActualWidth) / 2); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
var pp = mpos - (((FrameworkElement) item.Component).ActualWidth)/2; |
|
|
|
var pp = mpos - (((FrameworkElement) item.Component).ActualWidth)/2; |
|
|
|
var pos = (double)((Panel)item.Parent.Component).ActualWidth - pp - (((FrameworkElement)item.Component).ActualWidth); |
|
|
|
var pos = (double)((Panel)item.Parent.Component).ActualWidth - pp - (((FrameworkElement)item.Component).ActualWidth); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (container.Component is Grid) |
|
|
|
else if (container.Component is Grid) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case ArrangeDirection.Right: |
|
|
|
case ArrangeDirection.Right: |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (container.Component is Canvas) |
|
|
|
if (container.Component is Canvas) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) |
|
|
|
if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var pos = xmax - (double)((FrameworkElement)item.Component).ActualWidth; |
|
|
|
var pos = xmax - (double)((FrameworkElement)item.Component).ActualWidth; |
|
|
|
item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(pos); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(pos); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
var pos = (double)((Panel)item.Parent.Component).ActualWidth - xmax; |
|
|
|
var pos = (double)((Panel)item.Parent.Component).ActualWidth - xmax; |
|
|
|
item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (container.Component is Grid) |
|
|
|
else if (container.Component is Grid) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case ArrangeDirection.Top: |
|
|
|
case ArrangeDirection.Top: |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (container.Component is Canvas) |
|
|
|
if (container.Component is Canvas) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) |
|
|
|
if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ymin); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ymin); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
var pos = (double)((Panel)item.Parent.Component).ActualHeight - (ymin + (double)((FrameworkElement)item.Component).ActualHeight); |
|
|
|
var pos = (double)((Panel)item.Parent.Component).ActualHeight - (ymin + (double)((FrameworkElement)item.Component).ActualHeight); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (container.Component is Grid) |
|
|
|
else if (container.Component is Grid) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case ArrangeDirection.VerticalMiddle: |
|
|
|
case ArrangeDirection.VerticalMiddle: |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (container.Component is Canvas) |
|
|
|
if (container.Component is Canvas) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) |
|
|
|
if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ympos - (((FrameworkElement)item.Component).ActualHeight) / 2); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ympos - (((FrameworkElement)item.Component).ActualHeight) / 2); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
var pp = mpos - (((FrameworkElement)item.Component).ActualHeight) / 2; |
|
|
|
var pp = mpos - (((FrameworkElement)item.Component).ActualHeight) / 2; |
|
|
|
var pos = (double)((Panel)item.Parent.Component).ActualHeight - pp - (((FrameworkElement)item.Component).ActualHeight); |
|
|
|
var pos = (double)((Panel)item.Parent.Component).ActualHeight - pp - (((FrameworkElement)item.Component).ActualHeight); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (container.Component is Grid) |
|
|
|
else if (container.Component is Grid) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case ArrangeDirection.Bottom: |
|
|
|
case ArrangeDirection.Bottom: |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (container.Component is Canvas) |
|
|
|
if (container.Component is Canvas) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) |
|
|
|
if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var pos = ymax - (double)((FrameworkElement)item.Component).ActualHeight; |
|
|
|
var pos = ymax - (double)((FrameworkElement)item.Component).ActualHeight; |
|
|
|
item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(pos); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(pos); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
var pos = (double)((Panel)item.Parent.Component).ActualHeight - ymax; |
|
|
|
var pos = (double)((Panel)item.Parent.Component).ActualHeight - ymax; |
|
|
|
item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos); |
|
|
|
item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (container.Component is Grid) |
|
|
|
else if (container.Component is Grid) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
changeGroup.Commit(); |
|
|
|
changeGroup.Commit(); |
|
|
|
|
|
|
|
|
|
|
|
//_context.Services.Selection.SetSelectedComponents(null);
|
|
|
|
//_context.Services.Selection.SetSelectedComponents(null);
|
|
|
|
//_context.Services.Selection.SetSelectedComponents(items.ToList());
|
|
|
|
//_context.Services.Selection.SetSelectedComponents(items.ToList());
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|