Search This Blog

Showing posts with label Layout. Show all posts
Showing posts with label Layout. Show all posts

Monday, November 11, 2013

WPF Grid Example

WPF > Controls > Layout > Grid

Grid is a flexible grid area which contains columns and rows

Example:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid VerticalAlignment="Top" HorizontalAlignment="Left"  Width="400" Height="100">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition  />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>

        <TextBlock FontSize="20" FontWeight="Bold" Grid.ColumnSpan="3" Grid.Row="0" HorizontalAlignment="Center">Sales</TextBlock>
        <TextBlock FontSize="12" FontWeight="Bold" Grid.Row="1" Grid.Column="0">January</TextBlock>
        <TextBlock FontSize="12" FontWeight="Bold" Grid.Row="1" Grid.Column="1">February</TextBlock>
        <TextBlock FontSize="12" FontWeight="Bold" Grid.Row="1" Grid.Column="2">March</TextBlock>
        <TextBlock Grid.Row="2" Grid.Column="0">20000</TextBlock>
        <TextBlock Grid.Row="2" Grid.Column="1">30000</TextBlock>
        <TextBlock Grid.Row="2" Grid.Column="2">50000</TextBlock>
        <TextBlock FontSize="16" FontWeight="Bold" Grid.ColumnSpan="3" Grid.Row="3">Total : 100000</TextBlock>
    </Grid>
</Window>


StackPanel WPF

WPF > Controls > Layout > StackPanel

StackPanel arranges its elements into a single line that can be oriented horizontally or vertically.

Example:


XAML

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel>
        <Button Content="Button" Margin="0,0,385,0"/>
        <ComboBox Margin="0,0,211,0"/>
        <Label Content="Label"/>
        <TextBox Height="65" TextWrapping="Wrap" Text="TextBox"/>
    </StackPanel>
</Window>

Layout Controls WPF

WPF > Controls > Layout

Layout Controls WPF  contains elements that support application layout in Windows Presentation Foundation (WPF).