Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to implement "IRefreshable" using the Instance property of the DynamicComponent

$
0
0

I am new to C# Blazor and I'm trying to develop a working project of the

Learn .NET ASP.NET Core - Dynamically-rendered ASP.NET Core Razorcomponents

Example. I don't get the IRefreshable interface implemented correctly. I seem to be missing some steps.

Please see my code snippets.

Class for details of dynamic components invoked:

public class DynamicInvokedComponentDetails {     public required Type Component { get; set; }     public DynamicComponent? ComponentRef { get; set; } = null;     public Dictionary<string, object> Parameters { get; set; } = [];}

Parent component razor.cs (toolbar):

private string CurrentKey = string.Empty;// Component data and parametersprivate Dictionary<string, DynamicInvokedComponentDetails> Components => new() {     [tradeDebtors] = new DynamicInvokedComponentDetails()     {         Component = typeof(TransactionCriteria),         Parameters = []     },     [tradeCreditors] = new DynamicInvokedComponentDetails()     {         Component = typeof(TransactionCriteria),         Parameters = []     },     [transfers] = new DynamicInvokedComponentDetails()     {         Component = typeof(TransactionCriteria),         Parameters = []     } };private void OnToolBarButtonClick(string componentKey, SystemCategory systemCategory, TransactionCategory transactionCategory, MouseEventArgs Args){    if (Components["componentKey"].ComponentRef != null)    {        CurrentKey = string.Empty;        //**** Help required to implement this code        //**** Statement not working - IRefreshable not correctly implemented ****        //**** (Components["componentKey"].ComponentRef?.Instance as IRefreshable)?.Refresh();****        return;     }    CurrentKey = componentKey;    Components["componentKey"].Parameters =        new Dictionary<string, object>        {            ["SystemCategory"] = systemCategory,            ["TransactionCategory"] = transactionCategory        };}

Parent component .razor (toolbar):

@if (!string.IsNullOrEmpty(CurrentKey)){<DynamicComponent Type="@Components[CurrentKey].Component"                         Parameters="@Components[CurrentKey].Parameters"                         @ref="@Components[CurrentKey].ComponentRef" />}

Child component .razor (display transaction details):

public void Refresh(){     _windowVisible = true;     TransactionDetailWindowRef.Refresh();     //    StateHasChanged();}

Viewing all articles
Browse latest Browse all 4839

Trending Articles