Last active
June 28, 2022 04:58
-
-
Save usausa/623792f90631b4349b57c81151757e14 to your computer and use it in GitHub Desktop.
Blazor section
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ISectionCallback | |
{ | |
void SetMenu(RenderFragment value); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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