Silverlight专题(12) - 基于Silverlight的Live Search网页搜索
2008-11-17 11:50:15 来源:WEB开发网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}
Tags:Silverlight 专题 基于
编辑录入:爽爽 [复制链接] [打 印]- ››基于IP地址的vsftp服务器
- ››silverlight全屏显示图片
- ››基于MySQL 水平分区的优化示例
- ››基于CentOS5的Linux下pptp和openvpn的搭建及配置
- ››Silverlight MVVM 模式(一) 切近实战
- ››基于JavaScript的网页版塔防游戏
- ››基于Android平台 QQ大战360手机游戏爆红
- ››基于Windows Azure的云计算应用设计
- ››Silverlight for Windows Phone 7开发系列(1):...
- ››Silverlight for Windows Phone 7开发系列(2):...
- ››Silverlight for Windows Phone 7开发系列(3):...
- ››Silverlight for Windows Phone 7开发系列(4):...
更多精彩
赞助商链接