(牛人莫入)Silverlight 3 子表單調用WebService

來源:互聯網
上載者:User

等了好長的時間,SL3中文版本終於出來,抽周未有空來給體驗一下SL3;它對於RIA開發有很大的協助,開發上更簡單;對於過多的話我就不多說;先來看一個樣本吧:

這個樣本用到了SL3中的子表單,Web服務:先看運行結果吧:

 

開發步驟:

一、用Blend 3設計介面

說明:由於個人對美術不是很專長,所有在用Blend做介面,設計著色上不怎麼樣,望大家體諒;

 

二、項目整體搭建

這次主要是寫一些基礎性的東西,方便大家學習,同時也是對自身的提高,所有我的安排就是從控制項講起,

一步步升入;所以在後面還會有一些補充的東西;

三、WebService 代碼編寫

[WebMethod]       public string HelloWorld()       {           return "Hello World";       }       [WebMethod]       public string Say(string str)       {           return string.Format("你傳入的資料是{0}",str);                  }       [WebMethod]       public List<string> BindCombox()       {           List<string> list = new List<string>();           list.Add("四川");           list.Add("陝西");           list.Add("北京");           list.Add("上海");           return list;       }
四、引用Web服務到項目中,並調用
public void BindComBox()  {      MyServices.MyDataControlSoapClient Client = new CAO.SL3.Control.MyServices.MyDataControlSoapClient(); Client.BindComboxAsync(); Client.BindComboxCompleted += new EventHandler<CAO.SL3.Control.MyServices.BindComboxCompletedEventArgs> (Client_BindComboxCompleted);  }void Client_BindComboxCompleted(object sender, CAO.SL3.Control.MyServices.BindComboxCompletedEventArgs e)  {           cb.DataContext = e.Result;   }
 

在這裡要注意:與以前的調用有所不同,我在這裡也查了一下資料;會產生一個用戶端代理,用非同步去調用

五、在主表單中調用子表單
private void MyCombox_Click(object sender, RoutedEventArgs e)       {           Control.MyComBox combox = new CAO.SL3.Control.Control.MyComBox();           combox.Show();       }

就這幾步就完成了,沒有其它的步驟了;

希望能對剛用SL的新手有所協助,如果你是牛人就不要看了;本人的文字功底不長升,不擅長表達,如有不清,請看代碼

應該通解;

寫到這裡才知道還沒有吃飯,出去吃飯了,太餓了喲;回來在寫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.