【发布时间】:2009-01-13 17:14:38
【问题描述】:
我想知道如何使用模板数据绑定来完成以下代码生成的内容(带有一些关联文本的复选框网格):
int tbIndex = 0;
for (int i = 1; i < 5; i++) {
StackPanel pan = new StackPanel();
pan.Orientation = Orientation.Horizontal;
pan.Margin = new Thickness(3);
pan.Name = "RowPanel" + i;
for (int j = 0; j < 3; j++) {
CheckBox cb = new CheckBox();
TextBlock block = new TextBlock();
block.Width = 75;
block.Text = "Item " + (++tbIndex).ToString();
pan.Children.Add( cb );
pan.Children.Add( block );
}
ContentPanel.Children.Add( pan );
}
例如,在 ASP.NET 中,可以使用 DataList 并将重复方向设置为水平并绑定。有没有一种等效的方式,它的命令性和声明性更强(即预先使用模板完成并使用通用的“数据绑定”工具)?
【问题讨论】:
标签: data-binding xaml templates