Gtk.Expander Class
A container which can hide its child

See Also: Expander Members

Syntax

public class Expander : Bin

Remarks

A Gtk.Expander allows the user to hide or show its child by clicking on an expander triangle similar to the triangles used in a Gtk.TreeView.

Normally you use an expander as you would use any other descendant of Gtk.Bin; you create the child widget and use Container.Add() to add it to the expander. When the expander is toggled, it will take care of showing and hiding the child automatically.

C# Example

using System;
using Gtk;

class DemoExpander : Gtk.Window
{
        static void Main ()
        {
                Application.Init ();
                new DemoExpander ();
                Application.Run ();
        }

        DemoExpander () : base ("Demo Expander")
        {
                this.BorderWidth = 10;
                this.DeleteEvent += new DeleteEventHandler (OnWindowDelete);

                VBox vbox = new VBox ();
                vbox.PackStart (new Label ("Expander demo. Click on the triangle for details."), false, true, 3);

                Expander expander = new Expander ("Details");
                expander.Add (new Label ("Details can be shown or hidden."));
                vbox.PackStart (expander, false, true, 3);

                this.Add (vbox);
                this.ShowAll ();
        }

        void OnWindowDelete (object sender, DeleteEventArgs a)
        {
                Application.Quit ();
        }
}
  

Special Usage

There there are situations in which you may prefer to show and hide the expanded widget yourself, such as when you want to actually create the widget at expansion time. In this case, create a Gtk.Expander but do not add a child to it. The expander widget has Expander.Activated which can be used to monitor its expansion state.

C# Example

using System;
using Gtk;

class DemoExpander : Gtk.Window
{
        static void Main ()
        {
                Application.Init ();
                new DemoExpander ();
                Application.Run ();
        }

        DemoExpander () : base ("Demo Expander")
        {
                this.BorderWidth = 10;
                this.DeleteEvent += new DeleteEventHandler (OnWindowDelete);

                VBox vbox = new VBox ();
                vbox.PackStart (new Label ("Expander demo. Click on the triangle for details."), false, true, 3);

                Expander expander = new Expander ("Details");
                expander.Activated += new EventHandler (OnExpanded);
                vbox.PackStart (expander, false, true, 3);

                this.Add (vbox);
                this.ShowAll ();
        }

        void OnExpanded (object sender, EventArgs a)
        {
                Expander expander = sender as Expander;
                if (expander.Child == null)
                {
                        expander.Add (new Label ("Details can be shown or hidden."));
                        expander.ShowAll ();
                }
        }

        void OnWindowDelete (object sender, DeleteEventArgs a)
        {
                Application.Quit ();
        }
}
  

Requirements

Namespace: Gtk
Assembly: gtk-sharp (in gtk-sharp.dll)
Assembly Versions: 2.12.0.0
Since: Gtk# 2.4