WEB开发网
开发学院图形图像Flash Silverlight专题(12) - 基于Silverlight的Live ... 阅读

Silverlight专题(12) - 基于Silverlight的Live Search网页搜索

 2008-11-17 11:50:15 来源:WEB开发网   
核心提示: KeywordsCtl用于搜索词的输入SearchBtnCtl为搜索按钮WebNumCtl用来展示共搜索到多少条新闻WebPanelCtl用于展示得到的搜索结果其中WebPanelCtl用到了DataBinding(数据绑定)底层代码: Code1privatevoid SearchBtn

KeywordsCtl用于搜索词的输入

SearchBtnCtl为搜索按钮

WebNumCtl用来展示共搜索到多少条新闻

WebPanelCtl用于展示得到的搜索结果

其中WebPanelCtl用到了DataBinding(数据绑定)

底层代码:

Code

1privatevoid SearchBtnCtl_Click(object sender, RoutedEventArgs e)
2{
3   LiveSearchPortTypeClient liveSearchClient =new LiveSearchPortTypeClient();
4   SearchRequest webRequest =new SearchRequest();
5   webRequest.AppId ="44980C5CFA65792B3CDFF33A5CBF2CFAD17E3349";
6   webRequest.Market ="zh-CN";
7   webRequest.Version ="2.0";
8   webRequest.Sources =new SourceType[] { SourceType.Web };
9   webRequest.Query =this.KeywordsCtl.Text.Trim();
10   webRequest.Options =new SearchOption[] { SearchOption.EnableHighlighting };
11   webRequest.Web=new LiveSearchServiceRef.WebRequest();
12   webRequest.Web.Count =30;
13   webRequest.Web.CountSpecified =true;
14 
15   liveSearchClient.SearchAsync(webRequest);
16   liveSearchClient.SearchCompleted +=new EventHandler<SearchCompletedEventArgs>(liveSearchClient_SearchCompleted);
17}
18 
19void liveSearchClient_SearchCompleted(object sender, SearchCompletedEventArgs e)
20{
21   SearchResponse liveSearchResponse = e.Result;
22   LiveSearchServiceRef.WebResponse webResponse = liveSearchResponse.Web;
23   this.WebNumCtl.Text = String.Format("共{0}条搜索结果",webResponse.Total);
24   List<WebInfo> m_webInfoList =new List<WebInfo>();
25   if (webResponse.Results.Length >0)
26   {
27     foreach (WebResult webResult in webResponse.Results)
28     {
29       WebInfo webInfo =new WebInfo();
30       webInfo.Title = webResult.Title;
31       webInfo.Description = webResult.Description;
32       webInfo.PublishDateTime = webResult.DateTime;
33       webInfo.OriginalUrl = webResult.Url;
34       webInfo.DisplayUrl = webResult.DisplayUrl;
35       m_webInfoList.Add(webInfo);
36     }
37 
38     this.WebPanelCtl.ItemsSource = m_webInfoList;
39   }
40}

上一页  1 2 3 4  下一页

Tags:Silverlight 专题 基于

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接