From f1718c35c40d3182cc5e80a6a8ec533fc0ba7b4e Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 10 Mar 2007 21:25:26 +0000 Subject: [PATCH] allow resizing and deleting Grid rows and columns git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2442 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Controls/ControlStyles.xaml | 4 + .../Project/Controls/GridAdorner.cs | 186 ++++++++++++++++-- .../Project/DesignSurface.cs | 20 +- .../Extensions/CanvasPlacementSupport.cs | 3 +- .../Project/Extensions/GridAdornerProvider.cs | 32 +-- .../Extensions/GridPlacementSupport.cs | 83 ++++++++ .../WpfDesign.Designer/Project/ModelTools.cs | 22 ++- .../Project/WpfDesign.Designer.csproj | 1 + 8 files changed, 319 insertions(+), 32 deletions(-) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs 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 a61a9ac100..75e006d496 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml @@ -161,6 +161,8 @@ + + @@ -187,6 +189,8 @@ + + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/GridAdorner.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/GridAdorner.cs index 5eddad80b5..d8e86027d7 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/GridAdorner.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/GridAdorner.cs @@ -6,15 +6,13 @@ // using System; -using System.Collections.Generic; using System.Diagnostics; -using ICSharpCode.WpfDesign.Adorners; -using ICSharpCode.WpfDesign.Extensions; using System.Windows; using System.Windows.Controls; -using System.Windows.Shapes; -using System.Windows.Media; using System.Windows.Input; +using System.Windows.Media; + +using ICSharpCode.WpfDesign.Adorners; namespace ICSharpCode.WpfDesign.Designer.Controls { @@ -35,6 +33,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls readonly Orientation orientation; public const double RailSize = 10; + public const double RailDistance = 6; public const double SplitterWidth = 10; public GridRailAdorner(DesignItem gridItem, AdornerPanel adornerPanel, Orientation orientation) @@ -49,10 +48,10 @@ namespace ICSharpCode.WpfDesign.Designer.Controls if (orientation == Orientation.Horizontal) { this.Height = RailSize; - previewAdorner = new GridColumnSplitterAdorner(); + previewAdorner = new GridColumnSplitterAdorner(gridItem, null, null); } else { // vertical this.Width = RailSize; - previewAdorner = new GridRowSplitterAdorner(); + previewAdorner = new GridRowSplitterAdorner(gridItem, null, null); } previewAdorner.IsPreview = true; previewAdorner.IsHitTestVisible = false; @@ -70,14 +69,14 @@ namespace ICSharpCode.WpfDesign.Designer.Controls base.OnMouseMove(e); RelativePlacement rp = new RelativePlacement(); if (orientation == Orientation.Vertical) { - rp.XOffset = -RailSize; - rp.WidthOffset = RailSize; + rp.XOffset = -(RailSize + RailDistance); + rp.WidthOffset = RailSize + RailDistance; rp.WidthRelativeToContentWidth = 1; rp.HeightOffset = SplitterWidth; rp.YOffset = e.GetPosition(this).Y - SplitterWidth / 2; } else { - rp.YOffset = -RailSize; - rp.HeightOffset = RailSize; + rp.YOffset = -(RailSize + RailDistance); + rp.HeightOffset = RailSize + RailDistance; rp.HeightRelativeToContentHeight = 1; rp.WidthOffset = SplitterWidth; rp.XOffset = e.GetPosition(this).X - SplitterWidth / 2; @@ -95,6 +94,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls { base.OnMouseLeftButtonDown(e); e.Handled = true; + Focus(); adornerPanel.Children.Remove(previewAdorner); if (orientation == Orientation.Vertical) { using (ChangeGroup changeGroup = gridItem.OpenGroup("Split grid row")) { @@ -119,6 +119,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls rowCollection.CollectionElements[i].Properties[RowDefinition.HeightProperty].SetValue(newLength1); newRowDefinition.Properties[RowDefinition.HeightProperty].SetValue(newLength2); changeGroup.Commit(); + gridItem.Services.Selection.SetSelectedComponents(new DesignItem[] { newRowDefinition }, SelectionTypes.Auto); break; } } @@ -145,6 +146,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls newColumnDefinition.Properties[ColumnDefinition.WidthProperty].SetValue(newLength2); columnCollection.CollectionElements.Insert(i + 1, newColumnDefinition); changeGroup.Commit(); + gridItem.Services.Selection.SetSelectedComponents(new DesignItem[] { newColumnDefinition }, SelectionTypes.Auto); break; } } @@ -164,15 +166,126 @@ namespace ICSharpCode.WpfDesign.Designer.Controls #endregion } - public class GridSplitterAdorner : Control + public abstract class GridSplitterAdorner : Control { public static readonly DependencyProperty IsPreviewProperty = DependencyProperty.Register("IsPreview", typeof(bool), typeof(GridSplitterAdorner), new PropertyMetadata(SharedInstances.BoxedFalse)); + protected readonly Grid grid; + protected readonly DesignItem gridItem; + protected readonly DesignItem firstRow, secondRow; // can also be columns + + internal GridSplitterAdorner(DesignItem gridItem, DesignItem firstRow, DesignItem secondRow) + { + Debug.Assert(gridItem != null); + this.grid = (Grid)gridItem.Component; + this.gridItem = gridItem; + this.firstRow = firstRow; + this.secondRow = secondRow; + } + public bool IsPreview { get { return (bool)GetValue(IsPreviewProperty); } set { SetValue(IsPreviewProperty, SharedInstances.Box(value)); } } + + ChangeGroup activeChangeGroup; + double mouseStartPos; + bool mouseIsDown; + + protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) + { + e.Handled = true; + if (CaptureMouse()) { + Focus(); + gridItem.Services.Selection.SetSelectedComponents(new DesignItem[] { secondRow }, SelectionTypes.Auto); + mouseStartPos = GetCoordinate(e.GetPosition(grid)); + mouseIsDown = true; + } + } + + protected override void OnMouseMove(MouseEventArgs e) + { + if (mouseIsDown) { + double mousePos = GetCoordinate(e.GetPosition(grid)); + if (activeChangeGroup == null) { + if (Math.Abs(mousePos - mouseStartPos) + >= GetCoordinate(new Point(SystemParameters.MinimumHorizontalDragDistance, SystemParameters.MinimumVerticalDragDistance))) + { + activeChangeGroup = gridItem.OpenGroup("Change grid row/column size"); + RememberOriginalSize(); + } + } + if (activeChangeGroup != null) { + ChangeSize(mousePos - mouseStartPos); + } + } + } + + protected GridLength original1, original2; + protected double originalPixelSize1, originalPixelSize2; + + protected abstract double GetCoordinate(Point point); + protected abstract void RememberOriginalSize(); + protected abstract DependencyProperty RowColumnSizeProperty { get; } + + void ChangeSize(double delta) + { + // delta = difference in pixels + + if (delta < -originalPixelSize1) delta = -originalPixelSize1; + if (delta > originalPixelSize2) delta = originalPixelSize2; + + // replace Auto lengths with absolute lengths if necessary + if (original1.IsAuto) original1 = new GridLength(originalPixelSize1); + if (original2.IsAuto) original2 = new GridLength(originalPixelSize2); + + GridLength new1; + if (original1.IsStar && originalPixelSize1 > 0) + new1 = new GridLength(original1.Value * (originalPixelSize1 + delta) / originalPixelSize1, GridUnitType.Star); + else + new1 = new GridLength(original1.Value + delta); + GridLength new2; + if (original2.IsStar && originalPixelSize2 > 0) + new2 = new GridLength(original2.Value * (originalPixelSize2 - delta) / originalPixelSize2, GridUnitType.Star); + else + new2 = new GridLength(original2.Value - delta); + firstRow.Properties[RowColumnSizeProperty].SetValue(new1); + secondRow.Properties[RowColumnSizeProperty].SetValue(new2); + ((UIElement)VisualTreeHelper.GetParent(this)).InvalidateArrange(); + } + + protected override void OnMouseUp(MouseButtonEventArgs e) + { + if (activeChangeGroup != null) { + activeChangeGroup.Commit(); + activeChangeGroup = null; + } + Stop(); + } + + protected override void OnLostMouseCapture(MouseEventArgs e) + { + Stop(); + } + + protected override void OnKeyDown(KeyEventArgs e) + { + if (e.Key == Key.Escape) { + e.Handled = true; + Stop(); + } + } + + protected void Stop() + { + ReleaseMouseCapture(); + mouseIsDown = false; + if (activeChangeGroup != null) { + activeChangeGroup.Abort(); + activeChangeGroup = null; + } + } } public class GridRowSplitterAdorner : GridSplitterAdorner @@ -182,14 +295,61 @@ namespace ICSharpCode.WpfDesign.Designer.Controls DefaultStyleKeyProperty.OverrideMetadata(typeof(GridRowSplitterAdorner), new FrameworkPropertyMetadata(typeof(GridRowSplitterAdorner))); CursorProperty.OverrideMetadata(typeof(GridRowSplitterAdorner), new FrameworkPropertyMetadata(Cursors.SizeNS)); } + + + internal GridRowSplitterAdorner(DesignItem gridItem, DesignItem firstRow, DesignItem secondRow) : base(gridItem, firstRow, secondRow) + { + } + + protected override double GetCoordinate(Point point) + { + return point.Y; + } + + protected override void RememberOriginalSize() + { + RowDefinition r1 = (RowDefinition)firstRow.Component; + RowDefinition r2 = (RowDefinition)secondRow.Component; + original1 = (GridLength)r1.GetValue(RowDefinition.HeightProperty); + original2 = (GridLength)r2.GetValue(RowDefinition.HeightProperty); + originalPixelSize1 = r1.ActualHeight; + originalPixelSize2 = r2.ActualHeight; + } + + protected override DependencyProperty RowColumnSizeProperty { + get { return RowDefinition.HeightProperty; } + } } - public class GridColumnSplitterAdorner : GridSplitterAdorner + public sealed class GridColumnSplitterAdorner : GridSplitterAdorner { static GridColumnSplitterAdorner() { DefaultStyleKeyProperty.OverrideMetadata(typeof(GridColumnSplitterAdorner), new FrameworkPropertyMetadata(typeof(GridColumnSplitterAdorner))); CursorProperty.OverrideMetadata(typeof(GridColumnSplitterAdorner), new FrameworkPropertyMetadata(Cursors.SizeWE)); } + + internal GridColumnSplitterAdorner(DesignItem gridItem, DesignItem firstRow, DesignItem secondRow) : base(gridItem, firstRow, secondRow) + { + } + + protected override double GetCoordinate(Point point) + { + return point.X; + } + + protected override void RememberOriginalSize() + { + ColumnDefinition r1 = (ColumnDefinition)firstRow.Component; + ColumnDefinition r2 = (ColumnDefinition)secondRow.Component; + original1 = (GridLength)r1.GetValue(ColumnDefinition.WidthProperty); + original2 = (GridLength)r2.GetValue(ColumnDefinition.WidthProperty); + originalPixelSize1 = r1.ActualWidth; + originalPixelSize2 = r2.ActualWidth; + } + + protected override DependencyProperty RowColumnSizeProperty { + get { return ColumnDefinition.WidthProperty; } + } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs index 768272b8e1..77d27d6527 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs @@ -6,10 +6,11 @@ // using System; +using System.Collections.Generic; using System.Diagnostics; using System.Windows; -using System.Windows.Input; using System.Windows.Controls; +using System.Windows.Input; using System.Xml; using ICSharpCode.WpfDesign.Designer.Controls; @@ -58,7 +59,7 @@ namespace ICSharpCode.WpfDesign.Designer IUndoAction action = Func.First(undoService.UndoActions); Debug.WriteLine("Undo " + action.Title); undoService.Undo(); - _designContext.Services.Selection.SetSelectedComponents(action.AffectedElements); + _designContext.Services.Selection.SetSelectedComponents(GetLiveElements(action.AffectedElements)); } void OnUndoCanExecute(object sender, CanExecuteRoutedEventArgs e) @@ -73,7 +74,7 @@ namespace ICSharpCode.WpfDesign.Designer IUndoAction action = Func.First(undoService.RedoActions); Debug.WriteLine("Redo " + action.Title); undoService.Redo(); - _designContext.Services.Selection.SetSelectedComponents(action.AffectedElements); + _designContext.Services.Selection.SetSelectedComponents(GetLiveElements(action.AffectedElements)); } void OnRedoCanExecute(object sender, CanExecuteRoutedEventArgs e) @@ -81,6 +82,19 @@ namespace ICSharpCode.WpfDesign.Designer UndoService undoService = GetService(); e.CanExecute = undoService != null && undoService.CanRedo; } + + // Filters an element list, dropping all elements that are not part of the xaml document + // (e.g. because they were deleted). + static List GetLiveElements(ICollection items) + { + List result = new List(items.Count); + foreach (DesignItem item in items) { + if (ModelTools.IsInDocument(item)) { + result.Add(item); + } + } + return result; + } #endregion #region Command: Delete 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 7111d608a8..0015c61a06 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs @@ -10,9 +10,8 @@ using System.Collections.Generic; using System.Windows; using System.Windows.Controls; -using ICSharpCode.WpfDesign.Adorners; -using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Designer.Controls; +using ICSharpCode.WpfDesign.Extensions; namespace ICSharpCode.WpfDesign.Designer.Extensions { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridAdornerProvider.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridAdornerProvider.cs index 6937471573..39c47d5be5 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridAdornerProvider.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridAdornerProvider.cs @@ -7,14 +7,13 @@ using System; using System.Collections.Generic; -using ICSharpCode.WpfDesign.Adorners; -using ICSharpCode.WpfDesign.Extensions; using System.Windows; using System.Windows.Controls; -using System.Windows.Shapes; -using System.Windows.Media; using System.Windows.Threading; + +using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Designer.Controls; +using ICSharpCode.WpfDesign.Extensions; namespace ICSharpCode.WpfDesign.Designer.Extensions { @@ -22,7 +21,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions /// Allows arranging the rows/column on a grid. /// [ExtensionFor(typeof(Grid))] - public class GridAdornerProvider : PrimarySelectionAdornerProvider + [ExtensionServer(typeof(LogicalOrExtensionServer))] + public class GridAdornerProvider : AdornerProvider { sealed class RowSplitterPlacement : AdornerPlacement { @@ -31,9 +31,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize) { - adorner.Arrange(new Rect(-GridRailAdorner.RailSize, + adorner.Arrange(new Rect(-(GridRailAdorner.RailSize + GridRailAdorner.RailDistance), row.Offset - GridRailAdorner.SplitterWidth / 2, - GridRailAdorner.RailSize + adornedElementSize.Width, + GridRailAdorner.RailSize + GridRailAdorner.RailDistance + adornedElementSize.Width, GridRailAdorner.SplitterWidth)); } } @@ -46,9 +46,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize) { adorner.Arrange(new Rect(column.Offset - GridRailAdorner.SplitterWidth / 2, - -GridRailAdorner.RailSize, + -(GridRailAdorner.RailSize + GridRailAdorner.RailDistance), GridRailAdorner.SplitterWidth, - GridRailAdorner.RailSize + adornedElementSize.Height)); + GridRailAdorner.RailSize + GridRailAdorner.RailDistance + adornedElementSize.Height)); } } @@ -60,8 +60,12 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions leftBar = new GridRailAdorner(this.ExtendedItem, adornerPanel, Orientation.Vertical); topBar = new GridRailAdorner(this.ExtendedItem, adornerPanel, Orientation.Horizontal); - AdornerPanel.SetPlacement(leftBar, new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Stretch)); - AdornerPanel.SetPlacement(topBar, new RelativePlacement(HorizontalAlignment.Stretch, VerticalAlignment.Top)); + RelativePlacement rp = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Stretch); + rp.XOffset -= GridRailAdorner.RailDistance; + AdornerPanel.SetPlacement(leftBar, rp); + rp = new RelativePlacement(HorizontalAlignment.Stretch, VerticalAlignment.Top); + rp.YOffset -= GridRailAdorner.RailDistance; + AdornerPanel.SetPlacement(topBar, rp); adornerPanel.Children.Add(leftBar); adornerPanel.Children.Add(topBar); @@ -110,16 +114,18 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } splitterList.Clear(); Grid grid = (Grid)this.ExtendedItem.Component; + IList col = this.ExtendedItem.Properties["RowDefinitions"].CollectionElements; for (int i = 1; i < grid.RowDefinitions.Count; i++) { RowDefinition row = grid.RowDefinitions[i]; - GridRowSplitterAdorner splitter = new GridRowSplitterAdorner(); + GridRowSplitterAdorner splitter = new GridRowSplitterAdorner(this.ExtendedItem, col[i-1], col[i]); AdornerPanel.SetPlacement(splitter, new RowSplitterPlacement(row)); adornerPanel.Children.Add(splitter); splitterList.Add(splitter); } + col = this.ExtendedItem.Properties["ColumnDefinitions"].CollectionElements; for (int i = 1; i < grid.ColumnDefinitions.Count; i++) { ColumnDefinition column = grid.ColumnDefinitions[i]; - GridColumnSplitterAdorner splitter = new GridColumnSplitterAdorner(); + GridColumnSplitterAdorner splitter = new GridColumnSplitterAdorner(this.ExtendedItem, col[i-1], col[i]); AdornerPanel.SetPlacement(splitter, new ColumnSplitterPlacement(column)); adornerPanel.Children.Add(splitter); splitterList.Add(splitter); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs new file mode 100644 index 0000000000..af1ea9091b --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs @@ -0,0 +1,83 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.Windows; +using System.Windows.Controls; + +using ICSharpCode.WpfDesign.Adorners; +using ICSharpCode.WpfDesign.Extensions; +using ICSharpCode.WpfDesign.Designer.Controls; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + /// + /// Provides behavior for . + /// + [ExtensionFor(typeof(Grid))] + public sealed class GridPlacementSupport : BehaviorExtension, IPlacementBehavior + { + protected override void OnInitialized() + { + base.OnInitialized(); + this.ExtendedItem.AddBehavior(typeof(IPlacementBehavior), this); + } + + public bool CanPlace(ICollection childItems, PlacementType type, PlacementAlignment position) + { + return type == PlacementType.Delete; + } + + public void BeginPlacement(PlacementOperation operation) + { + } + + public void EndPlacement(PlacementOperation operation) + { + } + + public Rect GetPosition(PlacementOperation operation, DesignItem child) + { + return new Rect(); + } + + public void SetPosition(PlacementInformation info) + { + throw new NotImplementedException(); + } + + public bool CanLeaveContainer(PlacementOperation operation) + { + return true; + } + + public void LeaveContainer(PlacementOperation operation) + { + foreach (PlacementInformation info in operation.PlacedItems) { + if (info.Item.ComponentType == typeof(ColumnDefinition)) { + // TODO: combine the width of the deleted column with the previous column + this.ExtendedItem.Properties["ColumnDefinitions"].CollectionElements.Remove(info.Item); + } else if (info.Item.ComponentType == typeof(RowDefinition)) { + this.ExtendedItem.Properties["RowDefinitions"].CollectionElements.Remove(info.Item); + } else { + throw new NotImplementedException(); + } + } + } + + public bool CanEnterContainer(PlacementOperation operation) + { + return false; + } + + public void EnterContainer(PlacementOperation operation) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs index 0d6c420f96..83f782206e 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs @@ -44,6 +44,20 @@ namespace ICSharpCode.WpfDesign.Designer return 0; } + /// + /// Gets if the specified design item is in the document it belongs to. + /// + /// True for live objects, false for deleted objects. + public static bool IsInDocument(DesignItem item) + { + DesignItem rootItem = item.Context.RootItem; + while (item != null) { + if (item == rootItem) return true; + item = item.Parent; + } + return false; + } + /// /// Gets if the specified components can be deleted. /// @@ -60,9 +74,15 @@ namespace ICSharpCode.WpfDesign.Designer /// public static void DeleteComponents(ICollection items) { + DesignItem parent = Func.First(items).Parent; PlacementOperation operation = PlacementOperation.Start(items, PlacementType.Delete); try { - Func.First(items).Services.Selection.SetSelectedComponents(items, SelectionTypes.Remove); + ISelectionService selectionService = Func.First(items).Services.Selection; + selectionService.SetSelectedComponents(items, SelectionTypes.Remove); + // if the selection is empty after deleting some components, select the parent of the deleted component + if (selectionService.SelectionCount == 0 && !items.Contains(parent)) { + selectionService.SetSelectedComponents(new DesignItem[] { parent }); + } operation.DeleteItemsAndCommit(); } catch { operation.Abort(); 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 8e79ce8ae2..60bf8a752b 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj @@ -74,6 +74,7 @@ +