diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs index 91dbe48dd1..0f353d50b7 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs @@ -145,8 +145,10 @@ namespace ICSharpCode.WpfDesign.Designer Metadata.AddPopularProperty(TreeViewItem.IsSelectedProperty); Metadata.AddPopularProperty(Border.PaddingProperty); Metadata.AddPopularProperty(Shape.StretchProperty); - - Metadata.AddPopularProperty(Grid.RowProperty); + Metadata.AddPopularProperty(Control.VerticalContentAlignmentProperty); + Metadata.AddPopularProperty(Control.HorizontalContentAlignmentProperty); + + Metadata.AddPopularProperty(Grid.RowProperty); Metadata.AddPopularProperty(Grid.RowSpanProperty); Metadata.AddPopularProperty(Grid.ColumnProperty); Metadata.AddPopularProperty(Grid.ColumnSpanProperty); @@ -259,28 +261,30 @@ namespace ICSharpCode.WpfDesign.Designer Metadata.AddPopularControl(typeof(Viewport3D)); Metadata.AddPopularControl(typeof(WrapPanel)); + //Basic Metadata Size of double.NaN, means no Size should be set. + Metadata.AddDefaultSize(typeof(TextBlock), new Size(double.NaN, double.NaN)); + Metadata.AddDefaultSize(typeof(CheckBox), new Size(double.NaN, double.NaN)); + Metadata.AddDefaultSize(typeof(Image), new Size(double.NaN, double.NaN)); + Metadata.AddDefaultSize(typeof(UIElement), new Size(120, 100)); Metadata.AddDefaultSize(typeof(ContentControl), new Size(120, 20)); Metadata.AddDefaultSize(typeof(Button), new Size(75, 23)); + Metadata.AddDefaultSize(typeof(ToggleButton), new Size(75, 23)); - var s1 = new Size(120, 20); - Metadata.AddDefaultSize(typeof(Slider), s1); - Metadata.AddDefaultSize(typeof(TextBox), s1); - Metadata.AddDefaultSize(typeof(PasswordBox), s1); - Metadata.AddDefaultSize(typeof(ComboBox), s1); - Metadata.AddDefaultSize(typeof(ProgressBar), s1); + Metadata.AddDefaultSize(typeof(Slider), new Size(120, 20)); + Metadata.AddDefaultSize(typeof(TextBox), new Size(120, 20)); + Metadata.AddDefaultSize(typeof(PasswordBox), new Size(120, 20)); + Metadata.AddDefaultSize(typeof(ComboBox), new Size(120, 20)); + Metadata.AddDefaultSize(typeof(ProgressBar), new Size(120, 20)); - Metadata.AddDefaultSize(typeof(ToolBar), s1); - Metadata.AddDefaultSize(typeof(Menu), s1); + Metadata.AddDefaultSize(typeof(ToolBar), new Size(120, 20)); + Metadata.AddDefaultSize(typeof(Menu), new Size(120, 20)); - var s2=new Size(120,120); - Metadata.AddDefaultSize(typeof(InkCanvas),s2); - Metadata.AddDefaultSize(typeof(Image),s2); - Metadata.AddDefaultSize(typeof(TreeView),s2); + Metadata.AddDefaultSize(typeof(InkCanvas), new Size(120, 120)); + Metadata.AddDefaultSize(typeof(TreeView), new Size(120, 120)); - var s3=new Size(130,120); - Metadata.AddDefaultSize(typeof(Label),s3); - Metadata.AddDefaultSize(typeof(Expander),s3); + Metadata.AddDefaultSize(typeof(Label), new Size(130, 120)); + Metadata.AddDefaultSize(typeof(Expander), new Size(130, 120)); } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/AdornerLayer.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/AdornerLayer.cs index caef54e20c..e7912acdb5 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/AdornerLayer.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/AdornerLayer.cs @@ -225,7 +225,19 @@ namespace ICSharpCode.WpfDesign.Designer.Controls if (adorner.AdornedElement.IsDescendantOf(_designPanel)) { adorner.RenderTransform = (Transform)adorner.AdornedElement.TransformToAncestor(_designPanel); } - adorner.Arrange(new Rect(new Point(0, 0), adorner.DesiredSize)); + + //Fix Adorner Display of Image (or maybe other components...) + + var size = adorner.DesiredSize; + if (size.Height==0 && size.Width==0 && adorner.AdornedElement is FrameworkElement) + size = new Size(((FrameworkElement)adorner.AdornedElement).Width, ((FrameworkElement)adorner.AdornedElement).Height); + + if (double.IsNaN(size.Width)) + size.Width = 0; + if (double.IsNaN(size.Height)) + size.Height = 0; + + adorner.Arrange(new Rect(new Point(0, 0), size)); } return finalSize; } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs index a413005fb2..c3c43ec9e4 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs @@ -467,6 +467,12 @@ namespace ICSharpCode.WpfDesign.Designer UpdateContextMenu(); } + public void ClearContextMenu() + { + contextMenusAndEntries.Clear(); + ContextMenu = null; + } + private void UpdateContextMenu() { if (contextMenusAndEntries.Count == 0) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs index 63445ab1db..b9281df50d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs @@ -155,8 +155,9 @@ namespace ICSharpCode.WpfDesign.Designer { _designContext = context; _designPanel.Context = context; + _designPanel.ClearContextMenu(); - if (context.RootItem != null) { + if (context.RootItem != null) { _sceneContainer.Child = context.RootItem.View; } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs index bc776c99ca..b84847d33d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs @@ -81,8 +81,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } var p = new Point(x, y); - return new Rect(p, child.RenderSize); - } + //Fixes, Empty Image Resized to 0 + //return new Rect(p, child.RenderSize); + var size = item.View.RenderSize; + if (item.View is FrameworkElement) + size = new Size(((FrameworkElement)item.View).Width, ((FrameworkElement)item.View).Height); + return new Rect(p, size); + } public override void SetPosition(PlacementInformation info) { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs index cb17a58b81..3e70edd0cd 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs @@ -87,7 +87,12 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions if (item.View == null) return Rect.Empty; var p = item.View.TranslatePoint(new Point(), operation.CurrentContainer.View); - return new Rect(p, item.View.RenderSize); + //Fixes, Empty Image Resized to 0 + //return new Rect(p, item.View.RenderSize); + var size = item.View.RenderSize; + if (item.View is FrameworkElement) + size = new Size(((FrameworkElement) item.View).Width, ((FrameworkElement) item.View).Height); + return new Rect(p, size); } public virtual void BeforeSetPosition(PlacementOperation operation) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs index cc21ccfac4..c7dad43d77 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs @@ -121,22 +121,20 @@ namespace ICSharpCode.WpfDesign.Designer internal static void CreateVisualTree(this UIElement element) { - try { - element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); - element.Arrange(new Rect(element.DesiredSize)); - - //var fixedDoc = new FixedDocument(); - //var pageContent = new PageContent(); - //var fixedPage = new FixedPage(); - //fixedPage.Children.Add(element); - //(pageContent as IAddChild).AddChild(fixedPage); - //fixedDoc.Pages.Add(pageContent); - - //var f = new XpsSerializerFactory(); - //var w = f.CreateSerializerWriter(new MemoryStream()); - //w.Write(fixedDoc); - - //fixedPage.Children.Remove(element); + try + { + var fixedDoc = new FixedDocument(); + var pageContent = new PageContent(); + var fixedPage = new FixedPage(); + fixedPage.Children.Add(element); + (pageContent as IAddChild).AddChild(fixedPage); + fixedDoc.Pages.Add(pageContent); + + var f = new XpsSerializerFactory(); + var w = f.CreateSerializerWriter(new MemoryStream()); + w.Write(fixedDoc); + + fixedPage.Children.Remove(element); } catch (Exception) { } @@ -144,34 +142,29 @@ namespace ICSharpCode.WpfDesign.Designer internal static Size GetDefaultSize(DesignItem createdItem) { - CreateVisualTree(createdItem.View); + var defS = Metadata.GetDefaultSize(createdItem.ComponentType, false); + if (defS != null) + return defS.Value; - if (createdItem.View.GetType() == typeof (TextBlock)) - return new Size(double.NaN, double.NaN); + CreateVisualTree(createdItem.View); - var s = Metadata.GetDefaultSize(createdItem.ComponentType, false); + var s = createdItem.View.DesiredSize; + + var newS = Metadata.GetDefaultSize(createdItem.ComponentType, true); - if (double.IsNaN(s.Width) && createdItem.View.DesiredSize.Width > 0) - { - s.Width = createdItem.View.DesiredSize.Width; - } - if (double.IsNaN(s.Height) && createdItem.View.DesiredSize.Height > 0) - { - s.Height = createdItem.View.DesiredSize.Height; - } - - var newS = Metadata.GetDefaultSize(createdItem.ComponentType, true); + if (newS.HasValue) + { + if (!(s.Width > 0) && newS.Value.Width > 0) + s.Width = newS.Value.Width; - if (!(s.Width > 0)) - s.Width = newS.Width; + if (!(s.Height > 0) && newS.Value.Height > 0) + s.Height = newS.Value.Height; + } - if (!(s.Height > 0)) - s.Height = newS.Height; - - if (double.IsNaN(s.Width)) { + if (double.IsNaN(s.Width) && GetWidth(createdItem.View) > 0) { s.Width = GetWidth(createdItem.View); } - if (double.IsNaN(s.Height)) { + if (double.IsNaN(s.Height) && GetWidth(createdItem.View) > 0) { s.Height = GetHeight(createdItem.View); } @@ -230,11 +223,19 @@ namespace ICSharpCode.WpfDesign.Designer public DesignItem DesignItem { get; set; } } - private static ItemPos GetItemPos(DesignItem designItem) + private static ItemPos GetItemPos(IPlacementBehavior placementBehavior, DesignItem designItem) { var itemPos = new ItemPos() {DesignItem = designItem}; - if (designItem.Parent.Component is Canvas) + var pos = placementBehavior.GetPosition(null, designItem); + itemPos.Xmin = pos.X; + itemPos.Xmax = pos.X + pos.Width; + itemPos.Ymin = pos.Y; + itemPos.Ymax = pos.Y + pos.Height; + + return itemPos; + + if (designItem.Parent.Component is Canvas) { var canvas = designItem.Parent.View as Canvas; @@ -341,26 +342,31 @@ namespace ICSharpCode.WpfDesign.Designer var _context = collection.First().Context as XamlDesignContext; - var oldContainer = collection.First().Parent; + var container = collection.First().Parent; - if (collection.Any(x => x.Parent != oldContainer)) + if (collection.Any(x => x.Parent != container)) return; - - var newInstance = Activator.CreateInstance(containerType); + + //Change Code to use the Placment Operation! + var placement = container.Extensions.OfType().FirstOrDefault(); + if (placement == null) + return; + + var newInstance = Activator.CreateInstance(containerType); DesignItem newPanel = _context.Services.Component.RegisterComponentForDesigner(newInstance); var changeGroup = newPanel.OpenGroup("Wrap in Container"); List itemList = new List(); foreach (var item in collection) { - itemList.Add(GetItemPos(item)); - - if (oldContainer.Component is Canvas) { + itemList.Add(GetItemPos(placement, item)); + //var pos = placement.GetPosition(null, item); + if (container.Component is Canvas) { 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) { + } else if (container.Component is Grid) { item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).Reset(); item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).Reset(); item.Properties.GetProperty(FrameworkElement.MarginProperty).Reset(); @@ -374,21 +380,8 @@ namespace ICSharpCode.WpfDesign.Designer var xmax = itemList.Max(x => x.Xmax); var ymin = itemList.Min(x => x.Ymin); var ymax = itemList.Max(x => x.Ymax); - - if (oldContainer.Component is Canvas) { - newPanel.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(xmax - xmin); - newPanel.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(ymax - ymin); - newPanel.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(xmin); - newPanel.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ymin); - } else if (oldContainer.Component is Grid) { - newPanel.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).SetValue(HorizontalAlignment.Left); - newPanel.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).SetValue(VerticalAlignment.Top); - newPanel.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(new Thickness(xmin, ymin, 0, 0)); - newPanel.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(xmax - xmin); - newPanel.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(ymax - ymin); - } - - foreach (var item in itemList) { + + foreach (var item in itemList) { newPanel.ContentProperty.CollectionElements.Add(item.DesignItem); if (newPanel.Component is Canvas) { @@ -425,9 +418,16 @@ namespace ICSharpCode.WpfDesign.Designer } } - oldContainer.ContentProperty.CollectionElements.Add(newPanel); - - changeGroup.Commit(); + PlacementOperation operation = PlacementOperation.TryStartInsertNewComponents( + container, + new[] { newPanel }, + new[] { new Rect(xmin, ymin, xmax - xmin, ymax - ymin).Round() }, + PlacementType.AddItem + ); + + operation.Commit(); + + changeGroup.Commit(); _context.Services.Selection.SetSelectedComponents(new []{ newPanel }); } @@ -443,12 +443,16 @@ namespace ICSharpCode.WpfDesign.Designer if (collection.Any(x => x.Parent != container)) return; + var placement = container.Extensions.OfType().FirstOrDefault(); + if (placement == null) + return; + var changeGroup = container.OpenGroup("Arrange Elements"); List itemList = new List(); foreach (var item in collection) { - itemList.Add(GetItemPos(item)); + itemList.Add(GetItemPos(placement, item)); } var xmin = itemList.Min(x => x.Xmin); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs index 143ff20d57..359a4823a0 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs @@ -313,7 +313,7 @@ namespace ICSharpCode.WpfDesign /// Gets the default size for new controls of the specified type, /// or new Size(double.NaN, double.NaN) if no default size was registered. /// - public static Size GetDefaultSize(Type t, bool checkBasetype = true) + public static Size? GetDefaultSize(Type t, bool checkBasetype = true) { Size s; lock (defaultSizes) { @@ -324,7 +324,7 @@ namespace ICSharpCode.WpfDesign t = checkBasetype ? t.BaseType : null; } } - return new Size(double.NaN, double.NaN); + return null; } }