How to use .FitPage() ?

Hi,

I have a DiagramComponent that works fine, except I can't get the FitPage() to work.


I have a button that creates the DiagramComponent - it calls code like this:

// create connectors and nodes...
// then...
await traceDiagram?.DoLayout();
FitOptions fitOptions = new FitOptions()
{
Mode = FitMode.Both,
Region = DiagramRegion.PageSettings
};
traceDiagram?.FitToPage(fitOptions);


The diagram does not fit to the page, it remains too large to see everything in the viewport.

I have tried moving FitPage() before DoLayout() also, but that doesn't fit the page either.


If I create another button that lets me fit to page after the diagram is rendered then that works (the button calls traceDiagram.FitToPage() ).  But I want the diagram to be fitted when it is first rendered.

What am I doing wrong? Should FitPage() be executed at some other time?


Thanks.


1 Reply 1 reply marked as answer

SU Sumathi Uthayakumar Syncfusion Team November 25, 2022 07:30 AM UTC

Hi Paul,


We have prepared a sample based on your requirements. We met your requirement in the created event. When the Diagram component is rendered, the created event is triggered. In the Created event, you can invoke the Dolayout and Fittopage methods, which will fit the entire diagram into the current viewport. We have provided a sample for your reference. Also included is a code snippet for your reference.

    FitOptions fitOptions = new FitOptions()

  {

   Mode = FitMode.Both,

Region = DiagramRegion.PageSettings

};

    private void Oncreated ()

    {

        diagram.DoLayout();

        diagram.FitToPage(fitOptions);

    }













Regards,

Sumathi U.


Attachment: Forum179036_d0cbb93d.zip

Marked as answer
Loader.
Up arrow icon