我有一组动态生成的 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);
}