Page.xaml
Code
<UserControl x:Class="SilverlightApp.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="AntiqueWhite">
</Grid>
</UserControl>
<UserControl x:Class="SilverlightApp.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="AntiqueWhite">
</Grid>
</UserControl>
Page.xaml.cs
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApp
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
Dtable();
}
protected void Dtable()
{
int numrows = 3;
int numcells = 3;
for (int j = 0; j < numrows; j++)
{
RowDefinition rd = new RowDefinition();
LayoutRoot.RowDefinitions.Add(rd);
ColumnDefinition cd = new ColumnDefinition();
LayoutRoot.ColumnDefinitions.Add(cd);
for (int i = 0; i < numcells; i++)
{
TextBox tb = new TextBox();
tb.Width = 110;
tb.Height = 30;
tb.Text = "row " + j.ToString() + ", cell " + i.ToString();
LayoutRoot.Children.Add(tb);
LayoutRoot.SetValue(Grid.ShowGridLinesProperty, true); //显示网格
tb.SetValue(Grid.ColumnProperty, i);
tb.SetValue(Grid.RowProperty, j);
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApp
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
Dtable();
}
protected void Dtable()
{
int numrows = 3;
int numcells = 3;
for (int j = 0; j < numrows; j++)
{
RowDefinition rd = new RowDefinition();
LayoutRoot.RowDefinitions.Add(rd);
ColumnDefinition cd = new ColumnDefinition();
LayoutRoot.ColumnDefinitions.Add(cd);
for (int i = 0; i < numcells; i++)
{
TextBox tb = new TextBox();
tb.Width = 110;
tb.Height = 30;
tb.Text = "row " + j.ToString() + ", cell " + i.ToString();
LayoutRoot.Children.Add(tb);
LayoutRoot.SetValue(Grid.ShowGridLinesProperty, true); //显示网格
tb.SetValue(Grid.ColumnProperty, i);
tb.SetValue(Grid.RowProperty, j);
}
}
}
}
}