passing parameters between blazor components code example

Example 1: how to pass property between blazor components

public void ConfigureServices(IServiceCollection services)
{
    services.AddSingleton<Services.AppData>();
}

Example 2: how to pass property between blazor components

@inject Services.AppData AppData
<div style="width:300px; height:100px; background-color:@AppData.Color">
    <h3>Display Component</h3>
    <p>You entered the number @AppData.Number.</p>
</div>

@code {
    protected override void OnInitialized()
    {
        AppData.OnChange += StateHasChanged;
    }
}

Tags:

Misc Example