Layout Controls with Grid in code : Grid « Windows Presentation Foundation « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Windows Presentation Foundation » GridScreenshots 
Layout Controls with Grid in code
Layout Controls with Grid in code
  
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="" Height="300" Width="300"
    >
</Window>


//File:Window.xaml.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;


namespace WpfApplication1
{
    public partial class Window1 : System.Windows.Window
    {

        public Window1()
        {
            InitializeComponent();
            Grid g = new Grid();
            RowDefinition r = new RowDefinition();
            r.Height = new GridLength(0, GridUnitType.Auto);
            g.RowDefinitions.Add(r);
            r = new RowDefinition();
            r.Height = new GridLength(2, GridUnitType.Star);
            g.RowDefinitions.Add(r);
            r = new RowDefinition();
            r.Height = new GridLength(1, GridUnitType.Star);
            g.RowDefinitions.Add(r);

            ColumnDefinition c = new ColumnDefinition();
            c.Width = new GridLength(0, GridUnitType.Auto);
            g.ColumnDefinitions.Add(c);
            c = new ColumnDefinition();
            g.ColumnDefinitions.Add(c);

            TextBlock tb = new TextBlock();
            tb.Text = "Protocol:";
            Grid.SetColumn(tb, 0);
            Grid.SetRow(tb, 0);
            g.Children.Add(tb);

            tb = new TextBlock();
            tb.Text = "HyperText Transfer Protocol:";
            Grid.SetColumn(tb, 1);
            Grid.SetRow(tb, 0);
            g.Children.Add(tb);

            tb = new TextBlock();
            tb.Text = "Type:";
            Grid.SetColumn(tb, 0);
            Grid.SetRow(tb, 1);
            g.Children.Add(tb);

            tb = new TextBlock();
            tb.Text = "HTML Document";
            Grid.SetColumn(tb, 1);
            Grid.SetRow(tb, 1);
            g.Children.Add(tb);

            tb = new TextBlock();
            tb.Text = "Connection:";
            Grid.SetColumn(tb, 0);
            Grid.SetRow(tb, 2);
            g.Children.Add(tb);

            tb = new TextBlock();
            tb.Text = "Not encrypted";
            Grid.SetColumn(tb, 1);
            Grid.SetRow(tb, 2);
            g.Children.Add(tb);

            g.ShowGridLines = true;
            this.Content = g;
        }

    }
}

   
    
  
Related examples in the same category
1.GridSplitter ExampleGridSplitter Example
2.GridSplitter as Entire Column or RowGridSplitter as Entire Column or Row
3.ColumnDefinition.Width=AutoColumnDefinition.Width=Auto
4.ColumnDefinition.Width=*ColumnDefinition.Width=*
5.Grid With SplitterGrid With Splitter
6.Bind to Grid Width and HeightBind to Grid Width and Height
7.Simple Grid.xamlSimple Grid.xaml
8.Use Grid to layout a CalendarUse Grid to layout a Calendar
9.Grid with Rectangle and GeometryDrawingGrid with Rectangle and GeometryDrawing
10.Set Grid Row and Column for a ButtonSet Grid Row and Column for a Button
11.Arrange UI Elements in a GridArrange UI Elements in a Grid
12.Grid with Column Definition and Row definitionGrid with Column Definition and Row definition
13.Align Ellipses along with GridAlign Ellipses along with Grid
14.Use GridSplitterUse GridSplitter
15.Define rows / columns for GridDefine rows / columns for Grid
16.Using Grid.ColumnSpanUsing Grid.ColumnSpan
17.Set Grid Row Height and Column Width to AutoSet Grid Row Height and Column Width to Auto
18.Mixing row height stylesMixing row height styles
19.Show Grid LinesShow Grid Lines
20.Multiple Items in a Grid CellMultiple Items in a Grid Cell
21.Grid in ScrollViewerGrid in ScrollViewer
22.Margin vs Padding and GridMargin vs Padding and Grid
23.Without Panel.ZIndexWithout Panel.ZIndex
24.Panel.ZIndexPanel.ZIndex
25.Stretched GridSplitterStretched GridSplitter
26.Window with GridWindow with Grid
27.Arrange the children for GridArrange the children for Grid
28.Set Row Height and column Width for GridSet Row Height and column Width for Grid
29.Set Row and Column Index when Adding Buttons to GridSet Row and Column Index when Adding Buttons to Grid
30.Put more than one Object to one Grid CellPut more than one Object to one Grid Cell
31.Set Column and Row index when adding Controls to a GridSet Column and Row index when adding Controls to a Grid
32.Nested GridNested Grid
33.Shared Size GroupShared Size Group
34.Empty RowDefinition and ColumnDefinitionEmpty RowDefinition and ColumnDefinition
35.Grid Splitter and AlignmentGrid Splitter and Alignment
36.Use the Grid element to create a standard user interface (UI) dialog box.Use the Grid element to create a standard user interface (UI) dialog box.
37.Place and size rectangles and ellipses in Grid cellsPlace and size rectangles and ellipses in Grid cells
38.Use Image as the Grid backgroundUse Image as the Grid background
39.Automatic Width and HeightAutomatic Width and Height
40.Grid with SharedSizeGroupGrid with SharedSizeGroup
41.Layout a Form with StackPanel and GridLayout a Form with StackPanel and Grid
42.Clear All ColumnsClear All Columns
43.Clear All RowsClear All Rows
44.Remove One ColumnRemove One Column
45.Remove One RowRemove One Row
46.The current number of ColumnsThe current number of Columns
47.The current number of RowsThe current number of Rows
48.Remove 5 Columns with ColumnDefinitions.RemoveRangeRemove 5 Columns with ColumnDefinitions.RemoveRange
49.Remove 5 Row with RowDefinitions.RemoveRangeRemove 5 Row with RowDefinitions.RemoveRange
50.Contains RowContains Row
51.Contains Column?Contains Column?
52.Insert RowInsert Row
53.Insert ColumnInsert Column
54.Is Grid ReadOnlyIs Grid ReadOnly
55.Grid mouse down eventGrid mouse down event
56.Grid Preview mouse down eventGrid Preview mouse down event
57.Setting Grid row heights in codeSetting Grid row heights in code
58.Set control to specific row and column in codeSet control to specific row and column in code
59.Show Grid lines in codeShow Grid lines in code
60.Programmatically use the positioning methods of GridProgrammatically use the positioning methods of Grid
61.Add a ColumnDefinition to GridAdd a ColumnDefinition to Grid
62.Add a RowDefinition to GridAdd a RowDefinition to Grid
63.Grid PreviewMouseDown action and MouseDown actionGrid PreviewMouseDown action and MouseDown action
64.Grid MouseLeftButtonDown action and PreviewMouseLeftButtonDown actionGrid MouseLeftButtonDown action and PreviewMouseLeftButtonDown action
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.