How to close Radzen panel from code

I am using trying to use the panel to show/hide a set of configuration items from on a parent component that flow to the child on a button click I want to be able to collapse the RadzenPanel in this event but I am not able to do so. Warnings about setting a components parameters outside the component etc.

<RadzenPanel @ref="ConfigPanel" Collapsed="@ShowCollapsed"   AllowCollapse="true" class="bg-light"
             Expand=@(() => PanelCollapseChange("Expand")) Collapse=@(() => PanelCollapseChange("Collapse")) >
<HeaderTemplate> </HeaderTemplate>
<ChildContent></ChildContent>
</RadzenPanel>   
@code{

    public bool ShowCollapsed { get; set; } 


    void PanelCollapseChange(string Command)
    {
        if(Command == "Expand")
            ShowCollapsed = false;
        if(Command=="Collapse")
            ShowCollapsed= true;

    }
}

with this setup you can modify ShowCollapsed in code behind and it works as expected
the trick is that even though we have this binding

Collapsed="@ShowCollapsed"

without the code in the on changed event things don't stay in sync -- initial open --> close in code behind -->open from the [-]' stays open and will not close from code behind again

1 Like