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

Silverlight专题(13) - 基于Silverlight的Live Search资讯搜索

 2008-11-17 11:50:11 来源:WEB开发网   
核心提示: 底层的代码调用如下:Code1privatevoid SearchBtnCtl_Click(object sender, RoutedEventArgs e)2{3 this.SearchBtnCtl.IsEnabled =false;4 LiveSearchPortTypeClient

底层的代码调用如下:

Code

1privatevoid SearchBtnCtl_Click(object sender, RoutedEventArgs e)
2{
3   this.SearchBtnCtl.IsEnabled =false;
4   LiveSearchPortTypeClient liveSearchClient =new LiveSearchPortTypeClient();
5   SearchRequest webRequest =new SearchRequest();
6   webRequest.AppId ="44980C5CFA65792B3CDFF33A5CBF2CFAD17E3349";
7   webRequest.Market ="zh-CN";
8   webRequest.Version ="2.0";
9   webRequest.Sources =new SourceType[] { SourceType.News};
10   webRequest.Query =this.KeywordsCtl.Text.Trim();
11   webRequest.Options =new SearchOption[] { SearchOption.EnableHighlighting };
12 
13   liveSearchClient.SearchAsync(webRequest);
14   liveSearchClient.SearchCompleted +=new EventHandler<SearchCompletedEventArgs>(liveSearchClient_SearchCompleted);
15}
16 
17void liveSearchClient_SearchCompleted(object sender, SearchCompletedEventArgs e)
18{
19   SearchResponse liveSearchResponse = e.Result;
20 
21   //News Search
22   NewsResponse newsResponse = liveSearchResponse.News;
23   this.WebNumCtl.Text = String.Format("共{0}条搜索结果", newsResponse.Total);
24   List<NewsInfo> m_newsList =new List<NewsInfo>();
25   if (newsResponse.Results.Length >0)
26   {
27     foreach(NewsResult newsResult in newsResponse.Results)
28     {
29       NewsInfo newsInfo =new NewsInfo();
30       newsInfo.Title = newsResult.Title;
31       newsInfo.Source = newsResult.Source;
32       newsInfo.Snippet = newsResult.Snippet;
33       newsInfo.PublishDate = newsResult.Date;
34       newsInfo.OriginalUrl = newsResult.Url;
35       m_newsList.Add(newsInfo);
36     }
37 
38     this.NewsPanelCtl.ItemsSource= m_newsList;
39   }
40 
41   this.NewsPanelCtl.Visibility = Visibility.Visible;
42   this.SearchBtnCtl.IsEnabled =true;
43}

Tags:Silverlight 专题 基于

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