Nous allons partir sur exemple qui affiche deux boutons sur une fenêtre. Le code C# est trivial:
public partial class Window1 : Window
{
Button button1 = new Button();
Button button2 = new Button();
string content = "Hello";
DockPanel dockPanel = new DockPanel();
public Window1()
{
InitializeComponent();
dockPanel.Background = Brushes.Red;
dockPanel.LastChildFill = false;
this.AddChild(dockPanel);
button1.Background = Brushes.AliceBlue;
button1.Height = 50;
button1.Width = 100;
button1.Content = content;
DockPanel.SetDock(button1, Dock.Bottom);
button2.Background = Brushes.Aquamarine;
button2.Height = 50;
button2.Width = 100;
button2.Content = content;
DockPanel.SetDock(button2, Dock.Top);
this.dockPanel.Children.Add(button1);
this.dockPanel.Children.Add(button2);
}
On constate que la programmation fenêtrée est très hiérarchisée. En effet nous pouvons nettement distinguer une organisation de ce type :
Ainsi il est naturel qu'un langage hiérarchique tel que XML puisse parfaitement convenir pour représenter des interfaces graphiques.