My Blazor (.NET 8) page has a list of components generated one for each row in a database query response:
@foreach (var item in _listOfItems){<CollapsibleCard Title="item.CardTitle"> other contest based on item..</CollapsibleCard>}where CollapsibleCard is a component I made that shows the content in a card with a collapse/expand button.
I would like to have a button on the page that collapses or expands all the cards at once. The component has a method to collapse or expand it. What code can I put in the onclick handler for the button to go through all these cards?
For a fixed number of cards I could use @ref definition on each one, but not sure how that would work in this scenario where there could be any number of components.
NB. I have previously tried having a Parameter for the expanded/collapsed state, but generally found that approach not to work: the compiler gives warnings if you try to modify the value of a Parameter from inside the component (as would happen when the user clicks on the button in the card to expand it), and changing the value of the parameter from outside the component doesn't do anything as the component doesn't know to re-render itself, you would have to iterate over the components to re-render them anyway, or re-render the entire page.