To elaborate on the answer of henon, here is how I use CascadingValue
.
In my MainLayout.razor
, where I inject custom theme into <MudThemeProvider/>
<MudThemeProvider Theme="customTheme"/>
...
<MudMainContent>
<CascadingValue Value="@customTheme">
<div class="body-container">
@Body
</div>
</CascadingValue>
</MudMainContent>
...
@code {
MudTheme customTheme = new MudTheme()
{
Palette = new Palette()
{
Primary = new MudColor("011E41")
}
};
}
And then, in any other components down the hierarchy, I can use like this
<MudText Typo="Typo.h4" Style="@($"color:{Theme.Palette.Primary}")">
Example usage of the custom theme.
</MudText>
@code {
[CascadingParameter]
protected MudTheme Theme { get; set; }
}