Alignment Commands in WPF Diagram (SfDiagram)

Alignment commands are used to align the selected objects such as Nodes and Connectors on a page with respect to a reference object(first item in the selection list).

AlignLeft command

The AlignLeft command is used to align all the selected objects along the left corner of the reference object.

IGraphInfo graphinfo = diagramcontrol.Info as IGraphInfo;
// sets direction to Left
graphinfo.Commands.AlignLeft.Execute(null);

AlignRight command

The AlignRight command is used to align all the selected objects along the right corner of the reference object.

IGraphInfo graphinfo = diagramcontrol.Info as IGraphInfo;
// sets direction to Right
graphinfo.Commands.AlignRight.Execute(null);

AlignCenter command

The AlignCenter command is used to center all selected objects vertically. It aligns selected objects to the center with respect to the horizontal axis by changing the x-coordinate of the object.

IGraphInfo graphinfo = diagramcontrol.Info as IGraphInfo;
// sets direction to Center vertically
graphinfo.Commands.AlignCenter.Execute(null);

Gif for Align commands

AlignTop command

The AlignTop command is used to align all the selected objects along the top corner of the reference object.

IGraphInfo graphinfo = diagramcontrol.Info as IGraphInfo;
// sets direction to Top
graphinfo.Commands.AlignTop.Execute(null);

AlignBottom command

The AlignBottom command is used to align all the selected objects along the bottom corner of the reference object.

IGraphInfo graphinfo = diagramcontrol.Info as IGraphInfo;
// sets direction as Bottom
graphinfo.Commands.AlignBottom.Execute(null);

AlignMiddle command

The AlignMiddle command is used to center all selected objects horizontally. It aligns selected objects to the center with respect to the vertical axis by changing the y-coordinate of the object.

IGraphInfo graphinfo = diagramcontrol.Info as IGraphInfo;
// sets direction to Center horizontally
graphinfo.Commands.AlignCenter.Execute(null);

Gif for Align commands

View sample in GitHub