What is the correct way to initialize design time data

I’ve created a DesignTime helper class that can inject design time data into properties in my components. I’m having a hard time deciding where to load it though.

For instance, this doesn’t work:

protected override async Task OnInitializedAsync()

{

    #if RADZEN

        consultantCustomers = DesignTimeDataHelper.SampleConsultantCustomers;

        loaded = true;

    #else

        await Task.CompletedTask;

    #endif

}

But I can do blocks where I set it directly in the code block. This feels a bit messy though. Is there an overrided method that Radzen Studio / the Visual Studio extension executes while in design mode - or do I have to initialize and set the data as part of the initialization of the parameters in the code blocks, ie:

@code {

#if RADZEN

private List consultantCustomers = DesignTimeDataHelper.SampleConsultantCustomers;

#else

private List consultantCustomers = new List();

#endif

}

Hi @LostLogic,

Radzen Blazor Studio overrides all code from lifecycle methods by design. Code in OnInitializedAsync of the page shouldn't run in design time builds. Initializing in in the parameters is taken under consideration though. You can either have

private List consultantCustomers = new List();

or

private List consultantCustomers = null;

or

private List consultantCustomers;

Your approach should work too:

#if RADZEN

private List consultantCustomers = DesignTimeDataHelper.SampleConsultantCustomers;

#else

private List consultantCustomers = new List();

#endif

Why do you need design time specific data though? Radzen Blazor Studio should already provide such data if no initializer of the member is used.

I think I’m in need of looking at a few tutorials. I’m pretty sure I’m trying to force functionality that’s probably already baked in.

Without RADZEN blocks to load data:

When I add the designtime loading as discussed above, it comes to life:

I wager there is some work I need to do in the Data selection in the top left of the view to direct it to use design time data from my helper?

No, that's not needed in general. However if you have @if () blocks they are not true during design-time build it is likely that the inner content won't render.