GridUnitType Enumeration
Describes the kind of value that a GridLength object is holding.
Assembly: PresentationFramework (in PresentationFramework.dll)
Star sizing is used to distribute available space by weighted proportions. For additional information about this type of sizing, see Use Star Sizing Sample.
In Extensible Application Markup Language (XAML), star values are expressed as * or 2*. In the first case, the row or column would receive one times the available space; in the second case, the row or column would receive two times the available space, and so on.
This example shows how to create a standard user interface (UI) dialog box by using the Grid element.
The following example creates a dialog box like the Run dialog box in the Windows operating system.
The example creates a Grid and uses the ColumnDefinition and RowDefinition classes to define five columns and four rows.
The example then adds and positions an Image, RunIcon.png, to represent the image that is found in the dialog box. The image is placed in the first column and row of the Grid (the upper-left corner).
Next, the example adds a TextBlock element to the first column, which spans the remaining columns of the first row. It adds another TextBlock element to the second row in the first column, to represent the Open text box. A TextBlock follows, which represents the data entry area.
Finally, the example adds three Buttons to the final row, which represent the OK, Cancel, and Browse events.
'Create a Grid as the root Panel element. Dim myGrid As New Grid() myGrid.Height = 165 myGrid.Width = 425 myGrid.Background = Brushes.Gainsboro myGrid.ShowGridLines = True myGrid.HorizontalAlignment = Windows.HorizontalAlignment.Left myGrid.VerticalAlignment = Windows.VerticalAlignment.Top ' Define and Add the Rows and Columns. Dim colDef1 As New ColumnDefinition colDef1.Width = New GridLength(1, GridUnitType.Auto) Dim colDef2 As New ColumnDefinition colDef2.Width = New GridLength(1, GridUnitType.Star) Dim colDef3 As New ColumnDefinition colDef3.Width = New GridLength(1, GridUnitType.Star) Dim colDef4 As New ColumnDefinition colDef4.Width = New GridLength(1, GridUnitType.Star) Dim colDef5 As New ColumnDefinition colDef5.Width = New GridLength(1, GridUnitType.Star) myGrid.ColumnDefinitions.Add(colDef1) myGrid.ColumnDefinitions.Add(colDef2) myGrid.ColumnDefinitions.Add(colDef3) myGrid.ColumnDefinitions.Add(colDef4) myGrid.ColumnDefinitions.Add(colDef5) Dim rowDef1 As New RowDefinition rowDef1.Height = New GridLength(1, GridUnitType.Auto) Dim rowDef2 As New RowDefinition rowDef2.Height = New GridLength(1, GridUnitType.Auto) Dim rowDef3 As New Controls.RowDefinition rowDef3.Height = New GridLength(1, GridUnitType.Star) Dim rowDef4 As New RowDefinition rowDef4.Height = New GridLength(1, GridUnitType.Auto) myGrid.RowDefinitions.Add(rowDef1) myGrid.RowDefinitions.Add(rowDef2) myGrid.RowDefinitions.Add(rowDef3) myGrid.RowDefinitions.Add(rowDef4) ' Add the Image. Dim img1 As New Image img1.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri("runicon.png", UriKind.Relative)) Grid.SetRow(img1, 0) Grid.SetColumn(img1, 0) myGrid.Children.Add(img1) ' Add the main application dialog. Dim txt1 As New TextBlock txt1.Text = "Type the name of a program, document, or Internet resource, and Windows will open it for you." txt1.TextWrapping = TextWrapping.Wrap Grid.SetColumnSpan(txt1, 4) Grid.SetRow(txt1, 0) Grid.SetColumn(txt1, 1) myGrid.Children.Add(txt1) ' Add the second TextBlock Cell to the Grid. Dim txt2 As New TextBlock txt2.Text = "Open:" Grid.SetRow(txt2, 1) Grid.SetColumn(txt2, 0) myGrid.Children.Add(txt2) ' Add the TextBox control. Dim tb1 As New TextBox Grid.SetRow(tb1, 1) Grid.SetColumn(tb1, 1) Grid.SetColumnSpan(tb1, 5) myGrid.Children.Add(tb1) ' Add the Button controls. Dim button1 As New Button Dim button2 As New Button Dim button3 As New Button button1.Content = "OK" button1.Margin = New Thickness(10, 0, 10, 15) button2.Content = "Cancel" button2.Margin = New Thickness(10, 0, 10, 15) button3.Content = "Browse ..." button3.Margin = New Thickness(10, 0, 10, 15) Grid.SetRow(button1, 3) Grid.SetColumn(button1, 2) Grid.SetRow(button2, 3) Grid.SetColumn(button2, 3) Grid.SetRow(button3, 3) Grid.SetColumn(button3, 4) myGrid.Children.Add(button1) myGrid.Children.Add(button2) myGrid.Children.Add(button3) Me.Content = myGrid
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="Grid Run Dialog Sample" WindowWidth="425" WindowHeight="225"> <Grid Background="#DCDCDC" Width="425" Height="165" HorizontalAlignment="Left" VerticalAlignment="Top" ShowGridLines="True"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Image Grid.Column="0" Grid.Row="0" Source="RunIcon.png" /> <TextBlock Grid.Column="1" Grid.ColumnSpan="4" Grid.Row="0" TextWrapping="Wrap"> Type the name of a program, folder, document, or Internet resource, and Windows will open it for you. </TextBlock> <TextBlock Grid.Column="0" Grid.Row="1">Open:</TextBlock> <TextBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="5" /> <Button Margin="10, 0, 10, 15" Grid.Row="3" Grid.Column="2">OK</Button> <Button Margin="10, 0, 10, 15" Grid.Row="3" Grid.Column="3">Cancel</Button> <Button Margin="10, 0, 10, 15" Grid.Row="3" Grid.Column="4">Browse ...</Button> </Grid> </Page>
For the complete sample, see Standard UI Dialog Box Sample.
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.