A Simple Grid Control : Grid « Containers « Silverlight






A Simple Grid Control

A Simple Grid Control
    

<UserControl x:Class='SilverlightApplication3.MainPage'
    xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' 
    xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
    xmlns:d='http://schemas.microsoft.com/expression/blend/2008' 
    xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' 
    mc:Ignorable='d' 
    d:DesignWidth='640' 
    d:DesignHeight='480'>
      <Grid x:Name="LayoutRoot" Background="White">
           <Grid x:Name="gameBoard"
                Height="200"
                Width="200"
                Background="Gray">
          </Grid>
      </Grid>
  </UserControl>

//File: Page.xaml.cs

 using System;
 using System.Windows;
 using System.Windows.Controls;

 using System.Windows.Input;

 namespace SilverlightApplication3
 {
     public partial class MainPage : UserControl
     {
         public MainPage()
          {
             InitializeComponent();
             gameBoard.Loaded += new RoutedEventHandler(gameBoard_Loaded);
          }

         void gameBoard_Loaded(object sender, RoutedEventArgs e)
          {
             for (int y=0; y<10; y++){
                 for (int x=0; x<10; x++){
                     Button b = new Button();
                     b.Height = 20;
                     b.Width = 20;
                     b.Margin = new Thickness(x*20, y*20, 0, 0);
                     b.VerticalAlignment = VerticalAlignment.Top;
                     b.HorizontalAlignment = HorizontalAlignment.Left;
                     gameBoard.Children.Add(b);
                  }
             }
         }
     }
 }

   
    
    
    
  








Related examples in the same category

1.Positioning UI Elements with a GridPositioning UI Elements with a Grid
2.Span two rows and two columns with an Image control
3.Implementing a Grid to Set the Layout of Silverlight Controls
4.Grid exampleGrid example
5.ColumnSpan exampleColumnSpan example
6.Grid example 2* row and column definitionsGrid example 2* row and column definitions
7.Use Grid to layout a CalendarUse Grid to layout a Calendar
8.Set Grid Row and Column for a Button
9.Grid with Column Definition and Row definitionGrid with Column Definition and Row definition
10.Define rows / columns for GridDefine rows / columns for Grid
11.Using Grid.ColumnSpanUsing Grid.ColumnSpan
12.Set Grid Row Height and Column Width to AutoSet Grid Row Height and Column Width to Auto
13.Mixing row height stylesMixing row height styles
14.Show Grid LinesShow Grid Lines
15.Multiple Items in a Grid CellMultiple Items in a Grid Cell
16.Grid in ScrollViewerGrid in ScrollViewer
17.Margin vs Padding and Grid
18.ColumnDefinition.Width=Auto
19.Bind to Grid Width and Height
20.Set Row and Column Index when Adding Buttons to Grid
21.Put more than one Object to one Grid Cell
22.Set Column and Row index when adding Controls to a Grid
23.Empty RowDefinition and ColumnDefinition
24.Use the Grid element to create a standard user interface (UI) dialog box.
25.Place and size rectangles and ellipses in Grid cellsPlace and size rectangles and ellipses in Grid cells
26.Use Image as the Grid backgroundUse Image as the Grid background
27.Automatic Width and HeightAutomatic Width and Height
28.Layout Controls with Grid in codeLayout Controls with Grid in code
29.Set control to specific row and column in codeSet control to specific row and column in code
30.Show Grid lines in codeShow Grid lines in code
31.A basic Grid using star sizing.A basic Grid using star sizing.
32.A basic Grid using auto sizingA basic Grid using auto sizing
33.The basic syntax of a GridThe basic syntax of a Grid
34.Arranging content within a GridArranging content within a Grid
35.Proportional GridProportional Grid
36.Nested GridsNested Grids
37.Grid cell stretch modeGrid cell stretch mode
38.Programmatically adding a row and a column while setting the height and widthProgrammatically adding a row and a column while setting the height and width
39.Programmatically removing a row and a columnProgrammatically removing a row and a column
40.The basic syntax and usage of a GridSplitterThe basic syntax and usage of a GridSplitter
41.Star sizing GridStar sizing Grid
42.Grid mouse button up eventGrid mouse button up event