Error occured when debugging the programme i copied as a sample from others
You can call me marcus. I'm currently studying in a polytechnic in singapore and i'm doing my final year project. And my task is to create a application which is able to connect to my own server. Well, before i start off with anything, i did my research and came across a website, Building Your First Windows Phone App with Silverlight and Visual Studio 2010 Submitted by Alvin Ashcraft on Wed, 2010/03/24 - 9:30am. I have copied everything as at the webpage but my final result was that i had some errors and i'm not too sure why is that so. Would it be okay if you guys can tell me where have i gone wrong? Sorry but to trouble you guys. I am new to this programming and would hope to learn something from you guys. For any of your referrence, the webpage is http://dotnet.dzone.com/articles/building-your-first-windows?mz=27249-windowsphone7
This is the code i typed which is exactly the same on the webpage. But there were 3 error. The errors are as below.
The name 'XElement' does not exist in the current context
Mainpage.xaml.cs 49 27 The type of namespace name 'XElement' could not be found ( are you missing a using directive or an assembly reference?) Mainpage.xaml.cs 49 5 The type of namespace name 'XNamespace' could not be found ( are you missing a using directive or an assembly reference?) Mainpage.xaml.cs 50 5
The code of mine which i copied from the website is below. Really thank you if you could help me with this开发者_开发问答.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
namespace DotNetZoneReader
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;
}
private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
}
private void storyList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void button1_Click(object sender, RoutedEventArgs e)
{
var dzoneRss = new WebClient();
dzoneRss.DownloadStringCompleted += dzoneRss_DownloadStringCompleted;
dzoneRss.DownloadStringAsync(new Uri("http://feeds.dzone.com/zones/dotnet"));
}
private void dzoneRss_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null) return;
XElement xmlStories = XElement.Parse(e.Result);
XNamespace dz = "http://www.developerzone.com/modules/dz/1.0";
storyList.ItemsSource = from story in xmlStories.Descendants("item")
select new FeedItem
{
Title = story.Element("title").Value,
Description = story.Element("description").Value,
Link = story.Element("link").Value,
PublishDate = Convert.ToDateTime(story.Element(dz + "submitDate").Value).ToString("dd-MMM"),
Author = story.Element(dz + "submitter").Element(dz + "username").Value,
AuthorImageUrl = story.Element(dz + "submitter").Element(dz + "userimage").Value
};
}
public class FeedItem
{
public string Title { get; set; }
public string Description { get; set; }
public string Link { get; set; }
public string PublishDate { get; set; }
public string Author { get; set; }
public string AuthorImageUrl { get; set; }
}
}
}
Hope to hear from you soon and really appreciate if you can help me with it please and sorry to trouble you. :) Yours Sincerely, Marcus
Add this System.Xml.Linq
If you don't find this then add reference of this dll in your project first.
using System.Xml.Linq;
OR use it like this but above is better.
System.Xml.Linq.XElement
The problem is pointed out in the comment to that article:
Paul Millsaps replied on Thu, 2010/03/25 - 11:16am
Very nice article. One issue is the System.Linq.Xml above should actually be System.Xml.Linq, I believe. Thanks!
This means you must ensure that your project has a reference to System.Xml.Linq
(in the References node in Solution Explorer), and you also must have the line
using System.Xml.Linq;
in the using
directives area at the start of the code file.
精彩评论