【发布时间】:2010-09-05 16:11:36
【问题描述】:
我试图了解 XAML,并认为我会尝试编写一些代码。
尝试添加具有 6 x 6 列定义的网格,然后将文本块添加到其中一个网格单元格中。我似乎无法引用我想要的单元格。网格上没有我也可以添加文本块的方法。只有grid.children.add(object),没有Cell定义。
XAML:
<Page x:Class="WPF_Tester.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Page1"
Loaded="Page_Loaded">
</Page>
C#:
private void Page_Loaded(object sender, RoutedEventArgs e)
{
//create the structure
Grid g = new Grid();
g.ShowGridLines = true;
g.Visibility = Visibility.Visible;
//add columns
for (int i = 0; i < 6; ++i)
{
ColumnDefinition cd = new ColumnDefinition();
cd.Name = "Column" + i.ToString();
g.ColumnDefinitions.Add(cd);
}
//add rows
for (int i = 0; i < 6; ++i)
{
RowDefinition rd = new RowDefinition();
rd.Name = "Row" + i.ToString();
g.RowDefinitions.Add(rd);
}
TextBlock tb = new TextBlock();
tb.Text = "Hello World";
g.Children.Add(tb);
}
更新
这是一个令人毛骨悚然的地方:
在 XP 上使用 VS2008 Pro
WPFbrowser 项目模板(3.5 验证)
我没有得到自动完成中的方法。
【问题讨论】: