Tuesday 31 July 2012

Grid layout with Background Image in WPF

Introduction                              

The grid is a layout panel with Background Image that arranges its child controls in a tabular structure of rows and columns. Its functionality is similar to the HTML table but more flexible. A cell can contain multiple controls; they can span over multiple cells and even overlap themselves.

Description

To add controls to the grid layout panel just put the declaration between the opening and closing tags of the Grid. Keep in mind that the row- and column definitions must precced any definition of child controls.
The grid layout panel provides the two attached properties Grid. Column and Grid. Row to define the location of the control.




<Window x:Class="WpGridLayoutfApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        d:DesignHeight="350" d:DesignWidth="525" SizeToContent="WidthAndHeight">
    <Grid   >
        <Grid.Background>
            <ImageBrush ImageSource="bg.jpg"/>
        </Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />

        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions >
            <ColumnDefinition Width="Auto"  />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <Label Grid.Row="0" Grid.Column="0" Content="Name:" FontFamily="Trebuchet MS"
         FontWeight="Bold" FontSize="12" Foreground="White"/>
        <Label Grid.Row="1" Grid.Column="0" Content="E-Mail:" FontFamily="Trebuchet MS"
         FontWeight="Bold" FontSize="12" Foreground="White"/>
     
        <Label Grid.Row="0" Grid.Column="1" Content="Sunil Gurjar" FontFamily="Trebuchet MS"
         FontWeight="Bold" FontSize="12" Foreground="White"/>
        <Label Grid.Row="1" Grid.Column="1" Content="sunilgurjar19@gmail.com" FontFamily="Trebuchet MS"
         FontWeight="Bold" FontSize="12" Foreground="White"/>
      

    </Grid>
</Window>


Downloads  
You can download the complete source code in WPF C# 
 

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Blogger