When a window is added to WPF project then grid is added by default having zero children. It is most often used panel in compare to dock panel, stack panel and other panels. Grid provides no of rows and columns which enables you to arrange the elements without wrapping, stacking. It is like table in programming where we can add no of rows and columns as required.
Grid cells can be either left empty or multiple elements can also be placed in a single cell. Other panels like stack panel or wrap panel can also be used in the grid. Resizing the rows or columns can also be done using Grid Splitter. All this can be also performed by using code behind file.
Grid provides many more in-built functions like sharing width of a column, resizing cells, adding controls to grid and many more.
Canvas panel
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
</Grid>
We have to specify the position of each child using either Grid.Row or Grid.Column property of each child in this grid. If we not then it will place all the children in first cell by default.<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
</Grid>
Grid cells can be either left empty or multiple elements can also be placed in a single cell. Other panels like stack panel or wrap panel can also be used in the grid. Resizing the rows or columns can also be done using Grid Splitter. All this can be also performed by using code behind file.
Grid provides many more in-built functions like sharing width of a column, resizing cells, adding controls to grid and many more.
Canvas panel
Tidak ada komentar:
Posting Komentar