Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
动态创建多个组合框代码隐藏&;在silverlight中通过wcf绑定值_Wcf_Silverlight_Silverlight 4.0_Combobox - Fatal编程技术网

动态创建多个组合框代码隐藏&;在silverlight中通过wcf绑定值

动态创建多个组合框代码隐藏&;在silverlight中通过wcf绑定值,wcf,silverlight,silverlight-4.0,combobox,Wcf,Silverlight,Silverlight 4.0,Combobox,这是我为动态生成控件而编写的代码: private void GenCtrl(string type, int typeid,string sql) { string id = Convert.ToString(typeid); if (type == "TextBox") {// created for TextBox } el

这是我为动态生成控件而编写的代码:

private void GenCtrl(string type, int typeid,string sql)
            {
                string id = Convert.ToString(typeid);
            if (type == "TextBox")
                {// created for TextBox
                 }
           else if (type == "ComboBox")
                {
                  ComboBoxEdit  cb = new ComboBoxEdit();
                    cb.Name = "cb" + id; 
                 // this is to set unique id if more than 1 combobox created.

                   cb.Height = 20;
                    cb.Width = 100;
                    cb.Margin = new Thickness(2, 2, 0, 0);
                    cb.HorizontalAlignment = HorizontalAlignment.Left;
                    cb.Text = "Show All";
                    stctrl.Children.Add(cb);                       
                    ComboBoxEdit cbx = (ComboBoxEdit)cb.FindName(cb.Name);
                    cb.DisplayMember = "Name";

                    if(filsql !=null)
                    ServRef.GetComboBoxlistAsync(sql); //this would retrieve the list and attach to the combobox.

                    //ctlst.Add(cb.Name, type);
                }
}
//WCF服务参考


ServRef.GetComboBoxlistCompleted+=新事件处理程序(ServRef_getComboxListCompleted);
void ServRef_GetComboxListCompleted(对象发送方,GetComboxListCompletedEventArgs e)
{
cb.ItemsSource=e.结果;
cb.SelectedIndex=0;
}
绑定两个combobox时我面临的问题是创建了例如:cb1,cb2(动态创建)只有控件cb2 combox,它是最新在ServRef_GetComboBoxlistCompleted方法中激活的。我无法绑定第一个控件(combobox)的值


如果我的问题不清楚,请告诉我

我可以使用FindName找到

ComboBoxEdit cbx = (ComboBoxEdit)stackctrl.FindName(cb.Name);
ComboBoxEdit cbx = (ComboBoxEdit)stackctrl.FindName(cb.Name);