Home > Back-end >  Add additional parameter to event callback on parent page
Add additional parameter to event callback on parent page

Time:01-16

I use a component with a bool event callback OnCollapseChanged:

        <CollapsePanel CollapsedColor="@_collapsedColor"
                   OnCollapseChanged="OnCollapseChanged">
        </CollapsePanel>

This event callback calls a function in my C# code:


private bool _isCollapsed = false;

private Task OnCollapseChanged(bool state)
    {
        _isCollapsed = state;
        return Task.CompletedTask;
    }

As I use the CollapsePanel multiple times, I want to add something like an Id, but the component itself does (and should) not know anything about that ID, so what I want to do is something like that:

@foreach (var car in _carBaseStates)
{
        <CollapsePanel CollapsedColor="@_collapsedColor"
                   OnCollapseChanged="OnCollapseChanged(car.Id)">
        </CollapsePanel>
}

private HashSet<int> _collapsedIds = new HashSet<int>();

private Task OnCollapseChanged(bool state, int id)
    {
        if(state)
        {
            _collapsedIds.Add(id);
        }
        else
        {
            _collapsedIds.Remove(id);
        }
        return Task.CompletedTask;
    }

So basically, I want to add a parameter to the existing one, which is only known on my parent page.

CodePudding user response:

 <CollapsePanel CollapsedColor="@_collapsedColor"
                   OnCollapseChanged="(state)=>OnCollapseChanged(state,car.Id)">
 </CollapsePanel>
  • Related