对Scott Gu的Silverlight Sample--DiggSample的修改

由于Scott Gu的Sample中的数据已经不能获取,于是花了点时间把数据获取重写了下

仍然是Linq to XML,具体代码如下

  

XDocument xmlStories = XDocument.Parse(xmlContent);

XNamespace digg = "http://digg.com/docs/diggrss/";

XNamespace media = "http://search.yahoo.com/mrss/";

 

var stories = from story in xmlStories.Descendants("item")

              where story.Element(media + "thumbnail") != null &&

                    story.Element(media + "thumbnail").Attribute("url") != null &&

                    story.Element(media + "thumbnail").Attribute("url").Value.EndsWith(".jpg")

              select new DiggStory

              {

                  //Id = (int)story.Attribute("id"),

                  Title = ((string)story.Element("title")).Trim(),

                  Description = Regex.Replace(((string)story.Element("description")).Trim(), @"<(.[^>]*)>", "", RegexOptions.IgnoreCase),

                  ThumbNail = (string)story.Element(media + "thumbnail").Attribute("url"),

                  HrefLink = new Uri((string)story.Element("link")),

                  NumDiggs = (int)story.Element(digg + "diggCount"),

                  UserName = (string)story.Element(digg + "submitter").Element(digg + "username"),

              };

 

 

 还有一个地方,大家在做这个Demo的时候,注意在SL3中已经没有WateredTextBox,新的控件为DataPickerTextBox

 

 截图如下:

 

 [代码] 代码下载

posted @ 2009-12-12 22:09  rapid  阅读(345)  评论(1编辑  收藏  举报