WEB开发网
开发学院图形图像Flash 学Silverlight 2系列(25):综合实例之Live Sear... 阅读

学Silverlight 2系列(25):综合实例之Live Search

 2008-10-03 11:38:41 来源:WEB开发网   
核心提示: private void btnSearch_Click(object sender, RoutedEventArgs e){LiveSearchWebServiceSoapClient client = new LiveSearchWebServiceSoapClient();clien

private void btnSearch_Click(object sender, RoutedEventArgs e)
{
  LiveSearchWebServiceSoapClient client = new LiveSearchWebServiceSoapClient();
  client.DoSearchCompleted += new EventHandler<DoSearchCompletedEventArgs>(client_DoSearchCompleted);
  client.DoSearchAsync(this.txtQuery.Text);
}
void client_DoSearchCompleted(object sender, DoSearchCompletedEventArgs e)
{
  if (e.Error == null)
  {
    SearchResultItem[] results = e.Result as SearchResultItem[];
    HtmlElement result = HtmlPage.Document.GetElementById("result");
    foreach (SearchResultItem item in results)
    {
      HtmlElement itemElement = HtmlPage.Document.CreateElement("div");
      itemElement.CssClass = "itemstyle";
      HtmlElement titleElement = HtmlPage.Document.CreateElement("a");
      titleElement.SetAttribute("href",item.Url);
      titleElement.SetAttribute("innerText",item.Title);
      HtmlElement descriptElement = HtmlPage.Document.CreateElement("div");
      descriptElement.SetAttribute("innerText",item.Description);
      HtmlElement urlElement = HtmlPage.Document.CreateElement("span");
      urlElement.SetAttribute("innerText",item.Url);
      urlElement.CssClass = "urlstyle";
      itemElement.AppendChild(titleElement);
      itemElement.AppendChild(descriptElement);
      itemElement.AppendChild(urlElement);
      result.AppendChild(itemElement);
    }
  }
}

运行看一下效果,查询博客园:

学Silverlight 2系列(25):综合实例之Live Search

结束语

本文综合了前面关于浏览器集成以及数据与通信部分的内容,开发了一个综合的示例——Live Search。你可以下载本文示例代码。

上一页  1 2 3 4 

Tags:Silverlight 系列 综合

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