xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Grid_Run_Dialog.Window1"
Name="mainWindow" Loaded="onLoaded" Width="425" Height="200"/>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace Grid_Run_Dialog
{
public partial class Window1 : Window
{
Grid grid1 = new Grid ();
ColumnDefinition colDef1 = new ColumnDefinition();
ColumnDefinition colDef2 = new ColumnDefinition();
ColumnDefinition colDef3 = new ColumnDefinition();
ColumnDefinition colDef4 = new ColumnDefinition();
ColumnDefinition colDef5 = new ColumnDefinition();
RowDefinition rowDef1= new RowDefinition();
RowDefinition rowDef2= new RowDefinition();
RowDefinition rowDef3= new RowDefinition();
RowDefinition rowDef4= new RowDefinition();
TextBlock txt1 = new TextBlock();
TextBlock txt2 = new TextBlock();
Button button1= new Button();
Button button2= new Button();
Button button3= new Button();
TextBox tb1;
Image img1 = new Image();
void onLoaded(object sender, EventArgs e)
{
grid1.Background = Brushes.Gainsboro;
grid1.HorizontalAlignment = HorizontalAlignment.Left;
grid1.VerticalAlignment = VerticalAlignment.Top;
grid1.ShowGridLines = true;
grid1.Width = 425;
grid1.Height = 165;
colDef1.Width = new GridLength(1, GridUnitType.Auto);
colDef2.Width = new GridLength(1, GridUnitType.Star);
colDef3.Width = new GridLength(1, GridUnitType.Star);
colDef4.Width = new GridLength(1, GridUnitType.Star);
colDef5.Width = new GridLength(1, GridUnitType.Star);
grid1.ColumnDefinitions.Add(colDef1);
grid1.ColumnDefinitions.Add(colDef2);
grid1.ColumnDefinitions.Add(colDef3);
grid1.ColumnDefinitions.Add(colDef4);
grid1.ColumnDefinitions.Add(colDef5);
rowDef1.Height = new GridLength(1, GridUnitType.Auto);
rowDef2.Height = new GridLength(1, GridUnitType.Auto);
rowDef3.Height = new GridLength(1, GridUnitType.Star);
rowDef4.Height = new GridLength(1, GridUnitType.Auto);
grid1.RowDefinitions.Add(rowDef1);
grid1.RowDefinitions.Add(rowDef2);
grid1.RowDefinitions.Add(rowDef3);
grid1.RowDefinitions.Add(rowDef4);
img1.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("fil:///c:/image.png", UriKind.Relative));
Grid.SetRow(img1, 0);
Grid.SetColumn(img1, 0);
txt1.Text = "Text";
txt1.TextWrapping = TextWrapping.Wrap;
Grid.SetColumnSpan(txt1, 4);
Grid.SetRow(txt1, 0);
Grid.SetColumn(txt1, 1);
txt2.Text = "Open:";
Grid.SetRow(txt2, 1);
Grid.SetColumn(txt2, 0);
Grid.SetRow(tb1, 1);
Grid.SetColumn(tb1, 1);
Grid.SetColumnSpan(tb1, 5);
button1.Content = "OK";
button2.Content = "Cancel";
button3.Content = "Browse ...";
Grid.SetRow(button1, 3);
Grid.SetColumn(button1, 2);
button1.Margin = new Thickness(10, 0, 10, 15);
button2.Margin = new Thickness(10, 0, 10, 15);
button3.Margin = new Thickness(10, 0, 10, 15);
Grid.SetRow(button2, 3);
Grid.SetColumn(button2, 3);
Grid.SetRow(button3, 3);
Grid.SetColumn(button3, 4);
grid1.Children.Add(img1);
grid1.Children.Add(txt1);
grid1.Children.Add(txt2);
grid1.Children.Add(tb1);
grid1.Children.Add(button1);
grid1.Children.Add(button2);
grid1.Children.Add(button3);
mainWindow.Content = grid1;
}
}
}