Define rows / columns for Grid : Grid Row Column « Windows Presentation Foundation « C# / CSharp Tutorial






<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="186" Width="501">

<Grid ShowGridLines ="True" Background ="AliceBlue">

  <Grid.ColumnDefinitions>
    <ColumnDefinition/>
    <ColumnDefinition/>
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>
    <RowDefinition/>
    <RowDefinition/>
  </Grid.RowDefinitions>

  <Label Name="lblInstruction" Grid.Column ="0" Grid.Row ="0" FontSize="15">Enter</Label>
  <Button Name="btnOK"  Height ="30" Grid.Column ="0" Grid.Row ="0" >OK</Button>
  <Label Name="lblMake" Grid.Column ="1" Grid.Row ="0">Make</Label>
  <TextBox Name="txtMake" Grid.Column ="1" Grid.Row ="0" Width="193" Height="25"/>
  <Label Name="lblColor" Grid.Column ="0" Grid.Row ="1" >Color</Label>
  <TextBox Name="txtColor" Width="190" Height="25" Grid.Column ="0" Grid.Row ="1" />

  <Rectangle Fill ="LightGreen" Grid.Column ="1" Grid.Row ="1" />
  <Label Name="lblPetName" Grid.Column ="1" Grid.Row ="1" >Name</Label>
  <TextBox Name="txtPetName" Grid.Column ="1" Grid.Row ="1" Width="193" Height="25"/>

</Grid>
</Window>
WPF Define Rows Columns For Grid








24.43.Grid Row Column
24.43.1.ColumnDefinition.Width=AutoColumnDefinition.Width=Auto
24.43.2.ColumnDefinition.Width=*ColumnDefinition.Width=*
24.43.3.Bind to Grid Width and HeightBind to Grid Width and Height
24.43.4.Grid with Column Definition and Row definitionGrid with Column Definition and Row definition
24.43.5.Define rows / columns for GridDefine rows / columns for Grid
24.43.6.Using Grid.ColumnSpanUsing Grid.ColumnSpan
24.43.7.Set Grid Row Height and Column Width to AutoSet Grid Row Height and Column Width to Auto
24.43.8.Mixing row height stylesMixing row height styles
24.43.9.Set Column and Row index when adding Controls to a GridSet Column and Row index when adding Controls to a Grid
24.43.10.Empty RowDefinition and ColumnDefinitionEmpty RowDefinition and ColumnDefinition
24.43.11.Automatic Width and HeightAutomatic Width and Height
24.43.12.Span The Cells
24.43.13.Split Grid
24.43.14.Add controls to a Grid with loop
24.43.15.Set Grid Margin
24.43.16.Using Grid to layout all controls
24.43.17.Add control to specific row and column