Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor: render content only when visible

I have a blazor page with the folowing (simplified) component from Syncfusion that shows a modal form when a button is clicked:

<SfDialog IsModal="true" @bind-Visible="@IsFormVisible">
    <DialogTemplates>
        <Header>My Form</Header>
        <Content>
           <!-- complex and heavy content here -->
        </Content>
    </DialogTemplates>
</SfDialog>

<button @onclick="ShowDialog">Open Dialog</button>

@code {

    private void ShowDialog()
    {
         // How can I render form content here?
         @IsFormVisible = true;
    }

}

This form contains complex content that takes some time to render. Most of the time this form is not needed so rendering its content is not necessary.

How can I render form content only when the form is opened?

I've read about virtualization but it seems related only to large collections (lists/grids with hundreds of items), not to parts of code.

I'm looking for a generic blazor pattern not bound to Syncfusion components, but if this does not exist a Syncfusion dialog specific solution would be enough.

Thank you!

like image 653
Disti Avatar asked Jan 20 '26 17:01

Disti


1 Answers

How does this work?

<Content>
    @if(IsFormVisible)
    {        
       <!-- complex and heavy content here -->        
    }
</Content>
like image 79
Henk Holterman Avatar answered Jan 23 '26 19:01

Henk Holterman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!