This example resizes inner shapes when the associated parent container is resized. You can introduce the logic herein if you create custom shapes based on containers or use containers to group shapes.
-
Create a DiagramContainer class descendant to retain the behavior of standard containers:
public class CustomDiagramContainer : DiagramContainer { }
-
Handle the DiagramControl.BeforeItemsResizing event and pass container child items to the
e.Items
collection:private void DiagramControl1_BeforeItemsResizing(object sender, DiagramBeforeItemsResizingEventArgs e) { var containers = e.Items.OfType<CustomDiagramContainer>(); foreach (var customContainer in containers) { e.Items.Remove(customContainer); foreach (var item in customContainer.Items) e.Items.Add(item); } }
In this instance, the
DiagramControl
resizes these inner items instead of the parent container. -
Handle the DiagramControl.ItemsResizing event and correct container position and size:
private void DiagramControl1_ItemsResizing(object sender, DiagramItemsResizingEventArgs e) { var groups = e.Items.GroupBy(x => x.Item.ParentItem); foreach (var group in groups) { if (group.Key is CustomDiagramContainer) { var customContainer = (CustomDiagramContainer)group.Key; var containingRect = customContainer.Items.Select(x => x.RotatedDiagramBounds().BoundedRect()).Aggregate(Rect.Empty, Rect.Union); customContainer.Position = new Point(containingRect.X, containingRect.Y); customContainer.Width = (float)containingRect.Width; customContainer.Height = (float)containingRect.Height; } } }
- Containers and Lists
- Create Custom Diagram Items
- DiagramControl.BeforeItemsResizing
- DiagramControl.ItemsResizing
- WPF DiagramControl - Create Custom Shapes Based on Diagram Containers
- WPF DiagramControl - Create Rotatable Containers with Shapes
(you will be redirected to DevExpress.com to submit your response)