使用WCF在Silverlight中绑定组合框时出现问题 [英] Having issue binding combo-box in silverlight using WCF

查看:100
本文介绍了使用WCF在Silverlight中绑定组合框时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用WCF在Silverlight中绑定组合框.我试过下面的代码,但是comobobox不会显示任何值?? ..代码如下..

i am trying to bind combobox in silverlight using WCF. i have tried below code but comobobox doesn''t display any values??.. code as follows..

     public class Appsrvvice : IAppsrvvice
     {
       
        public void DoWork()
        {
         }

        public List<fillupcombox> fillup()
        {
            List<string> x=new List<string>();
            List<string> y=new List<string>();

            string connectionstring = "server=localhost;User Id=root;password=root;Persist Security Info=True;database=mv_store";
            string msg;

             msg = "";
            MySqlConnection con = new MySqlConnection(connectionstring);
            MySqlDataAdapter ad = new MySqlDataAdapter("select Product_Name,Product_Id from product_detail Order by Product_Name", con);

            DataTable dt = new DataTable();

            try
            {
                ad.Fill(dt);
              //  return dt;

                for(int i=0;i<dt.Rows.Count;i++)
                {
                    x.Add(dt.Rows[i]["Product_Name"].ToString());
                    y.Add(dt.Rows[i]["Product_Id"].ToString());
                }

            }

            catch (Exception e)
            {

                msg = e.Message;
                return null;

            }
            finally
            {
                ad.Dispose();
            }


            return new List<fillupcombox>()
            {
                new fillupcombox()
                {
                    Texts=x,
                    Valuess=y
                }
            };
        }
    }



    [ServiceContract]
    public interface IAppsrvvice
    {

        [OperationContract]
        void DoWork();

        [OperationContract]
        List<fillupcombox> fillup();

    }

    [DataContract]
    public class fillupcombox
    {

        [DataMember]
        public List<string> Texts
        {
            get;
            set;
        }

        [DataMember]
        public List<string> Valuess
        {
            get;
            set;

        }

    }

Heres My main page code

     public MainPage()
       
     {
            InitializeComponent();

            ServiceReference1.AppsrvviceClient obj = new ServiceReference1.AppsrvviceClient();
            obj.fillupCompleted += new EventHandler<ServiceReference1.fillupCompletedEventArgs>(fillupCompletedp);
            obj.fillupAsync();
            
           

        }


        public void fillupCompletedp(object sender, ServiceReference1.fillupCompletedEventArgs e)
        {
            

             comboBox1.ItemsSource =e.Result;
          

        }




组合框中未填充任何值.任何想法我错了吗?




No Values is populated in the combobox. Any idea where i am wrong?

推荐答案


在上面的代码fillupcombo(WCF DataContract)中,它是用户定义的数据类型,其中包含两个String列表,因此在silverlight应用程序中,您需要提及要将数据绑定到ComboBox的那个类型.只需在silverlight fillupCompleted事件中进行更改,强制为跟随,那么它将起作用

System.Collections.ObjectModel.ObservableCollection< ServiceReference1.fillupcombox> mylist = e.Result;

cmbxList.ItemsSource = mylist [0] .Texts;



问候
西拉子(Siraz)
Hi
In the above code fillupcombo ( WCF DataContract) it is userdefined datatype which contains two List of String , so in silverlight app you need to mention which one you need to bind the data to the ComboBox.Just make the change in silverlight fillupCompleted event compelted as follows then it will work

System.Collections.ObjectModel.ObservableCollection <ServiceReference1.fillupcombox> mylist = e.Result;

cmbxList.ItemsSource = mylist[0].Texts;



Regards
Siraz


这篇关于使用WCF在Silverlight中绑定组合框时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆