I have this renderfragment that I am assigning as a menu and I need to be able to clear the list from within this renderfragment and I can’t seem to get it to work. I have tried event callbacks, actions, delagates and everytime I run into this error: Keyword ‘this’ is not available in the current context. I also cannot pass any parameters through the builder it gives me this error: Cannot convert initializer type ‘lambda expression’ to target type ‘Microsoft.AspNetCore.Components.RenderFragment’. So how can I clear this list in this context? The problem is within the button: ClearListAction(). This also doesnt work: OnCLick=(() => webhookList.Clear()) I get the same error about ‘this’.
public delegate void ClearWebhooksAction(); // Delegate for clearing
public static ClearWebhooksAction ClearListAction { get; set; } // Delegate reference
public RenderFragment menu =
@<Menu>
@if (webhookList.Count > 0)
{
<MudTabs Elevation="0" Rounded="true" ApplyEffectsToContainer="true" Centered="true" PanelClass="mud-tabs-overlay" MinimumTabWidth="100%">
<MudTabPanel Icon="@Icons.Material.Filled.Phishing" Text="Webhooks">
@foreach (var n in webhookList)
{
string routerLink = "/cryptos/" + n.Id;
ClearListAction = () => webhookList.Clear();
<MenuItem RouterLink=@routerLink Class="notifications">
<MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceEvenly">
<div style="flex:20%">
<Avatar size="40px" src="@n.Avatar"/>
</div>
<div style="flex:65%">@n.Subtitle</div>
<div style="flex:15%">
@if (n.IsActive)
{
<MudIcon Icon="@Icons.Material.Outlined.NotificationsActive" Color="MudBlazor.Color.Info" Style="font-size:20px;text-align: right" Title="Favorite" Class="notifications"/>
}
else
{
<MudIcon Icon="@Icons.Material.Outlined.AddAlert" Color="MudBlazor.Color.Info" Style="font-size:20px;text-align: right" Title="Favorite" Class="notifications"/>
}
</div>
</MudStack>
</MenuItem>
}
@if (webhookList.Count > 0)
{
<div class="dismiss">
**<MudButton Class="list-button" Variant="Variant.Outlined" Size="MudBlazor.Size.Small" Color="MudBlazor.Color.Primary" OnClick="@(() => ClearListAction())" Style="font-size:14px !important">Dismiss</MudButton>**
</div>
}
</MudTabPanel>
<MudTabPanel Icon="@Icons.Material.Filled.CurrencyBitcoin" Text="Positions">
@foreach (var n in positionList)
{
string routerLink = "/cryptos/" + n.Id;
<MenuItem RouterLink=@routerLink Class="notifications">
<MudStack Row="true" AlignItems="AlignItems.Center">
<td>
<Avatar size="30px" src="@n.Avatar"/>
</td>
<td>@n.Subtitle</td>
<td>
@if (n.IsActive)
{
<MudIcon Icon="@Icons.Material.Outlined.NotificationsActive" Color="MudBlazor.Color.Info" Style="font-size:20px;text-align: right" Title="Favorite" Class="notifications"/>
}
else
{
<MudIcon Icon="@Icons.Material.Outlined.AddAlert" Color="MudBlazor.Color.Info" Style="font-size:20px; text-align: right" Title="Favorite" Class="notifications"/>
}
</td>
</MudStack>
</MenuItem>
}
@* @if(positionList.Count > 0) *@
@* { *@
@* <div class="dismiss"> *@
@* <MudButton Variant="Variant.Outlined" Size="MudBlazor.Size.Small" Color="MudBlazor.Color.Primary">Dismiss</MudButton> *@
@* </div> *@
@* } *@
</MudTabPanel>
</MudTabs>
}
else
{
<MenuItem Style="padding: 1rem;">
No notificaions to display
</MenuItem>
}
</Menu>;
it is passed like this in my blazor code:
<Dropdown Overlay=@menu Placement="AntDesign.Placement.Bottom" Class="notifications" Arrow>
<MudBadge Content="@(notificationCount)" Color="MudBlazor.Color.Primary" Overlap="true" Origin="Origin.CenterRight">
<Icon Type="bell" Theme="outline" OnClick="() => OpenDrawer(MudBlazor.Anchor.End)"/>
</MudBadge>
</Dropdown>