Skip to content

Instantly share code, notes, and snippets.

@usausa
Last active June 28, 2022 04:58
Show Gist options
  • Save usausa/623792f90631b4349b57c81151757e14 to your computer and use it in GitHub Desktop.
Save usausa/623792f90631b4349b57c81151757e14 to your computer and use it in GitHub Desktop.
Blazor section
@page "/"
<PageTitle>Index</PageTitle>
<MudText Typo="Typo.h3" GutterBottom="true">Hello, world!</MudText>
<Section>
<Menu>
<MudIconButton Icon="@Icons.Material.Filled.Person" Color="Color.Inherit" Link="" />
</Menu>
</Section>
public interface ISectionCallback
{
void SetMenu(RenderFragment value);
}
@inherits LayoutComponentBase
@implements ISectionCallback
<CascadingValue Value="this">
<MudLayout>
<MudAppBar Dense="true">
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" />
<MudSpacer />
@menu
</MudAppBar>
<MudDrawer @bind-Open="drawerOpen" Elevation="1">
<MudDrawerHeader Dense="true">
<MudText Typo="Typo.h6">Section</MudText>
</MudDrawerHeader>
<NavMenu />
</MudDrawer>
<MudMainContent>
<MudContainer MaxWidth="MaxWidth.Large" Class="my-2 pt-2">
@Body
</MudContainer>
</MudMainContent>
</MudLayout>
</CascadingValue>
@code {
private RenderFragment? menu;
public void SetMenu(RenderFragment? value)
{
menu = value;
StateHasChanged();
}
}
public sealed class Section : ComponentBase, IDisposable
{
[CascadingParameter]
public ISectionCallback Callback { get; set; } = default!;
[Parameter]
public RenderFragment Menu { get; set; } = default!;
protected override void OnInitialized()
{
Callback.SetMenu(Menu);
}
public void Dispose()
{
Callback.SetMenu(null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment