我有一组动态生成的WPF控件。如何动态分配这些控件的Tag属性? 我创建了这样的控件:
SchlEntities db = new SchlEntities();
InitializeComponent();
var controls = from stud in db.Students
orderby stud.GroupID
group stud by stud.GroupID into gr
select gr;
foreach (var gr in controls)
{
CreateComboBox();
}
private void CreateComboBox()
{
ComboBox combox = new ComboBox();
combox.Width = 280;
combox.Height = 30;
combox.Background = Brushes.LightBlue;
combox.Margin = new Thickness(5);
stackpanel.Children.Add(combox);
}