FitToPage Command in WPF Diagram

The FitToPage command is used to bring the entire diagram into view. The FitToPageParameter parameter is used to customize the FitToPage command behavior. If the parameter is null, the entire diagram fits into view.

<Button Height="50" Content="FitToPage" Name="FitToPage" Command="Syncfusion:DiagramCommands.FitToPage"></Button>
//Initialize the Diagram 
SfDiagram diagramcontrol = new SfDiagram();

IGraphInfo graphinfo = diagramcontrol.Info as IGraphInfo;
// To fit the Diagram into the view
graphinfo.Commands.FitToPage.Execute(null);

FitToPageParameter

The FitToPageParameter parameter is used to customize the FitToPage command behavior. If the parameter is null, the entire diagram fits into the view.

CanZoomIn

The CanZoomIn is used to set whether small diagrams are zoomed to fit the view or not.

CanZoomIn

FitToPage

The FitToPage is used to enable or disable the fit to page behavior with respect to height or width.

Values Description
None It is used to disable the FitToPage behavior.
FitToHeight It is used to enable the fit to page behavior only with respect to height.
FitToWidth It is used to enable the fit to page behavior only with respect to width.
FitToPage It is used to enable the fit to page behavior with respect to both height and width of the diagram.

FitToPage

Region

The Region is used to set the region where the FitToPage command should be applied in the diagram.

Values Description
Content It is used to perform fit to page for the content area only.
PageSettings It is used to perform fit to page based on the page width and page height.
Custom It is used to perform fit to page for custom region.

When the Region property is set to Custom, you must define the FocusArea property to specify the region that should be fitted into the view. Without a valid FocusArea, the custom fit-to-page operation cannot determine the target region.

FocusArea

The FocusArea is used to set the focus area to execute the FitToPage command in a custom region.

The following example shows how to create a FitToPageParameter instance and pass it to the FitToPage command.

//Initialize the Diagram 
SfDiagram diagram = new SfDiagram();

IGraphInfo graphinfo = diagram.Info as IGraphInfo;

graphinfo.Commands.FitToPage.Execute(
    new FitToPageParameter()
    {
        // To fit the diagram with respect to both width and height.
        FitToPage = FitToPage.FitToPage
    });

Region

View sample in GitHub

See Also

How to apply margin values to FitToPage command?

How to Fit Selected Nodes and Connectors to the WPF Diagram Window?