Put a simple StatusBar on the bottom with DockPanel

image_pdfimage_print


   
      

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Fun with Panels!" Height="291" Width="529">

  <DockPanel LastChildFill ="True">
    <Menu DockPanel.Dock ="Top" HorizontalAlignment="Left" Background="White">
      <MenuItem Header="_File">
        <Separator/>
        <MenuItem Header ="_Exit" />
      </MenuItem>
    </Menu>
    <StatusBar Name="statBar" DockPanel.Dock ="Bottom" 
               VerticalAlignment="Bottom" Background="Beige" >
      <StatusBarItem>
        <TextBlock>Ready</TextBlock>
      </StatusBarItem>
    </StatusBar>

    <StackPanel Background="LightSteelBlue" Orientation ="Vertical" DockPanel.Dock ="Left">
      <Label Name="lblInstruction" FontSize="15">Information</Label>
      <Label Name="lblMake">Make</Label>
      <TextBox Name="txtMake"/>
      <Label Name="lblColor">Color</Label>
      <TextBox Name="txtColor"/>
      <Label Name="lblPetName">Name</Label>
      <TextBox Name="txtPetName"/>
      <Button Name="btnOK">OK</Button>
    </StackPanel>
  
    <TextBlock Background ="LemonChiffon" FontSize ="20">test</TextBlock>
  </DockPanel>
</Window>

   
    
    
    
    
    
     


DockPanel Fill

image_pdfimage_print


   
      

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Dock Panel Demo"
    >
    <DockPanel>
      <Button DockPanel.Dock="Top">1</Button>
      <Button DockPanel.Dock="Left">2</Button>
      <Button DockPanel.Dock="Bottom">3</Button>
      <Button DockPanel.Dock="Right">4</Button>
      <Button >5</Button> <!-- Fill -->
    </DockPanel>
</Window>

   
    
    
    
    
    
     


DockPanel with Menu, ToolBarTray, StatusBar, StackPanel

image_pdfimage_print


   
       

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="DockPanelWindow" Height="300" Width="300">
    <DockPanel x:Name="dockPanel1">
        <Menu DockPanel.Dock="Top">
            <MenuItem Header="_File"/>
            <MenuItem Header="_Edit"/>
            <MenuItem Header="_Help"/>
        </Menu>
        <ToolBarTray Background="White" DockPanel.Dock="Top">
            <ToolBar Band="1" BandIndex="1">
                <Button>A</Button>
                <Button>B</Button>
                <Separator/>
                <Button>C</Button>
            </ToolBar>
        </ToolBarTray>
        <StatusBar DockPanel.Dock="Bottom">
            <StatusBarItem>
                <TextBlock>Ready</TextBlock>
            </StatusBarItem>
        </StatusBar>
        <StackPanel DockPanel.Dock="Left">
            <Expander Header="Useful">
                <StackPanel>
                    <Button>A</Button>
                    <Button>B</Button>
                    <Button>C</Button>
                </StackPanel>
            </Expander>
            <Expander Header="Less useful"></Expander>
            <Expander Header="Silly"></Expander>
        </StackPanel>
        <Button Padding="10 10">
            <TextBlock TextWrapping="Wrap" TextAlignment="Center">not docked</TextBlock>
        </Button>
    </DockPanel>
</Window>

   
    
    
    
    
    
    
     


LayoutPanels Basic Dialog Box

image_pdfimage_print


   
       
<Window x:Class="LayoutPanels.BasicDialogBox"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="BasicDialogBox" Height="300" Width="300" MinHeight="150" MinWidth="200">
  <DockPanel LastChildFill="True">
    <StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Right" Orientation="Horizontal">
      <Button Margin="10,10,2,10" Padding="3,3,3,3">OK</Button>
      <Button Margin="2,10,10,10" Padding="3,3,3,3">Cancel</Button>
    </StackPanel>
    <TextBox DockPanel.Dock="Top" Margin="10">This is a test.</TextBox>
  </DockPanel>
</Window>

   
    
    
    
    
    
    
     


Dock more than two objects

image_pdfimage_print


   
       
<Window x:Class="LayoutPanels.SimpleDock"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="SimpleDock" Height="300" Width="300"
    >
    <DockPanel LastChildFill="True">
      <Button DockPanel.Dock="Top">A Stretched Top Button</Button>
      <Button DockPanel.Dock="Top" HorizontalAlignment="Center">A Centered Top Button</Button>
      <Button DockPanel.Dock="Top" HorizontalAlignment="Left">A Left-Aligned Top Button</Button>
      <Button DockPanel.Dock="Bottom">Bottom Button</Button>
      <Button DockPanel.Dock="Left">Left Button</Button>
      <Button DockPanel.Dock="Right">Right Button</Button>
      <Button >Remaining Space</Button>
    </DockPanel>
</Window>

   
    
    
    
    
    
    
     


Docking left and right before top and bottom

image_pdfimage_print


   
             

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Simple DockPanel"
      Width="250" Height="150">
<DockPanel>
  <Button DockPanel.Dock="Left">Left</Button>
  <Button DockPanel.Dock="Right">Right</Button>
  <Button DockPanel.Dock="Top">Top</Button>
  <Button DockPanel.Dock="Bottom">Bottom</Button>
  <Button>Fill</Button>
</DockPanel>
</Window>

   
    
    
    
    
    
    
    
    
    
    
    
    
     


Show the effect of each value of the Dock property by manipulating two Rectangle elements.

image_pdfimage_print


   
  

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      x:Class="WpfApplication1.Page1"
      WindowTitle="Docking Sample">
  <DockPanel Background="White">
    <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Margin="0,0,0,10">
      <Button Click="OnClick1" Background="LightCoral">Dock = "Left"</Button>
      <Button Click="OnClick2" Background="LightCoral">Dock = "Right"</Button>
      <Button Click="OnClick3" Background="LightCoral">Dock = "Top"</Button>
      <Button Click="OnClick4" Background="LightCoral">Dock = "Bottom"</Button>
      <Button Click="OnClick5" Background="LightSkyBlue" Foreground="White">Dock = "Left"</Button>
      <Button Click="OnClick6" Background="LightSkyBlue" Foreground="White">Dock = "Right"</Button>
      <Button Click="OnClick7" Background="LightSkyBlue" Foreground="White">Dock = "Top"</Button>
      <Button Click="OnClick8" Background="LightSkyBlue" Foreground="White">Dock = "Bottom"</Button>
      <Button Click="OnClick9" Background="White">LastChildDock="True"</Button>
      <Button Click="OnClick10" Background="White">LastChildDock="False"</Button>
    </StackPanel>

    <Border Background="LightGoldenRodYellow" BorderBrush="Black" BorderThickness="1">
      <DockPanel Name="AnotherDockPanel">
        <Rectangle Name="rect1" MinWidth="200" MinHeight="200" Stroke="Black" Fill="LightCoral" />
        <Rectangle Name="rect2" MinWidth="200" MinHeight="200" Stroke="Black" Fill="LightSkyBlue" />
      </DockPanel>
    </Border>
  </DockPanel>
</Page>

//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Navigation;

namespace WpfApplication1
{
    public partial class Page1 : Page
    {
        public void OnClick1(object sender, RoutedEventArgs e)
        {
            DockPanel.SetDock(rect1, Dock.Left);
        }
       
        public void OnClick2(object sender, RoutedEventArgs e)
        {
            DockPanel.SetDock(rect1, Dock.Right);
        }

        public void OnClick3(object sender, RoutedEventArgs e)
        {
            DockPanel.SetDock(rect1, Dock.Top);
        }

        public void OnClick4(object sender, RoutedEventArgs e)
        {
            DockPanel.SetDock(rect1, Dock.Bottom);
        }

        public void OnClick5(object sender, RoutedEventArgs e)
        {
            DockPanel.SetDock(rect2, Dock.Left);
        }

        public void OnClick6(object sender, RoutedEventArgs e)
        {
            DockPanel.SetDock(rect2, Dock.Right);
        }

        public void OnClick7(object sender, RoutedEventArgs e)
        {
            DockPanel.SetDock(rect2, Dock.Top);
        }

        public void OnClick8(object sender, RoutedEventArgs e)
        {
            DockPanel.SetDock(rect2, Dock.Bottom);
        }

        public void OnClick9(object sender, RoutedEventArgs e)
        {
            AnotherDockPanel.LastChildFill = true;
        }

        public void OnClick10(object sender, RoutedEventArgs e)
        {
            AnotherDockPanel.LastChildFill = false;
        }
    }
}