Gtk.Viewport Class
A Gtk.Container that allows a scrollable view of its child when added to a Gtk.ScrolledWindow.

See Also: Viewport Members


public class Viewport : Bin


To scroll correctly, a Gtk.ScrolledWindow ordinarily requires explicit support from the Gtk.Widget that will be scrolled. However, a Viewport adds scrolling capabilities to an arbitrary child widget. For example, you can add a collection of widgets to a Gtk.Table container. By simply placing the Gtk.Table in a Viewport, you need only add the Viewport to a Gtk.ScrolledWindow to visually scroll the contents of your Table.

The "model" of this widget consists of horizontal and vertical Gtk.Adjustment objects. These do not need to be explicitly set to use the Viewport. Packing a child widget as demonstrated in the example, below, is all that is required.

The appearance of the Viewport can be adjusted using the Viewport.ShadowType property.

The following example creates a Gtk.Table in a Viewport. When placed in a small Gtk.Window, the widgets can be scrolled.

C# Example

namespace GtkSamples {
        using Gtk;
        using System;
        public class ViewportApp  {
                public static ScrolledWindow CreateViewport()
                        ScrolledWindow scroller = new ScrolledWindow();
                        Viewport viewer = new Viewport();
                        Table widgets = new Table(1, 2, false);
                        widgets.Attach(new Entry("This is example Entry 1"), 0, 1, 0, 1);
                        widgets.Attach(new Entry("This is example Entry 2"), 1, 2, 0, 1);
                        // Place the widgets in a Viewport, and the Viewport in a ScrolledWindow
                        return scroller;
                public static int Main (string[] args)
                        Application.Init ();
                        Window win = new Window ("Viewport Tester");
                        win.SetDefaultSize (180, 50);
                        win.DeleteEvent += new DeleteEventHandler (Window_Delete);
                        ScrolledWindow scroller = CreateViewport();
                        win.Add (scroller);
                        win.ShowAll ();
                        Application.Run ();
                        return 0;
                static void Window_Delete (object obj, DeleteEventArgs args)
                        Application.Quit ();
                        args.RetVal = true;



Namespace: Gtk
Assembly: gtk-sharp (in gtk-sharp.dll)
Assembly Versions: