Arranges child elements into a single line that can be oriented horizontally or vertically.

Namespace: DigitalRune.Game.UI.Controls
Assembly: DigitalRune.Game.UI (in DigitalRune.Game.UI.dll) Version: 1.1.0.0 (1.1.1.9392)

Syntax

C#
public class StackPanel : Panel
Visual Basic
Public Class StackPanel _
	Inherits Panel
Visual C++
public ref class StackPanel : public Panel

Examples

The following examples shows how to create a button containing an icon and a text label.
C# Copy imageCopy
// Create a horizontal stack panel containing an icon and a label.
var buttonContentPanel = new StackPanel { Orientation = Orientation.Horizontal };

buttonContentPanel.Children.Add(new Image
{
  Width = 16,
  Height = 16,
  Texture = content.Load<Texture2D>("Icons"),   // Load existing texture.
  SourceRectangle = new Rectangle(0, 0, 16, 16) // Optional: Select region in texture.
});

buttonContentPanel.Children.Add(new TextBlock
{
  Margin = new Vector4F(4, 0, 0, 0),
  Text = "Label",
  VerticalAlignment = VerticalAlignment.Center,
});

var button = new Button
{
  Content = buttonContentPanel,
  Margin = new Vector4F(4),
};

// To show the button, add it to an exising content control or panel.
panel.Children.Add(button);

// To handle button clicks simply add an event handler to the Click event.
button.Click += OnButtonClicked;

Inheritance Hierarchy

See Also