在WPF控件上动态分配Tag属性

时间:2012-07-10 08:35:41

标签: c# wpf tags wpf-controls

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

0 个答案:

没有答案