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> @foreach (var n in webhookList)<div class="flex"><div style="flex:20%"><Avatar size="40px" src="@n.Avatar"/></div><div style="flex:65%">@n.Subtitle</div></div> } @if (webhookList.Count > 0) { ClearListAction = () => webhookList.Clear();<div class="dismiss"><MudButton OkClick="@(() => webhookList.Clear())">Dismiss</MudButton></div> }</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>