UI/Components/PanelSwitcher.razor

A UI Razor component that inherits Panel and manages switching which child panel is visible. It tracks an active Panel, hides newly added children except the first, and toggles a "hidden" CSS class to show or hide children when switching.

NetworkingHttp Calls
@using Sandbox;
@using Sandbox.UI;
@inherits Panel
@namespace Sandbox

<root></root>

@code
{
    Panel _active;

    public Panel ActivePanel
    {
        get => _active;
        set => SwitchToPanel(value );
    }

    protected override void OnChildAdded(Panel child)
    {
        base.OnChildAdded(child);

        if ( ChildrenCount == 1 )
        {
            SwitchToPanel(child);
        }
        else
        {
            child.AddClass("hidden");
        }
    }

    public void SwitchToPanel( Panel panel )
    {
        _active = panel;

        foreach ( var child in Children )
        {
            child.SetClass("hidden", child != panel);
        }
    }
}