Converting Windows Phone to Windows 8: Listing 3

MainPageViewModel class.

public class MainPageViewModel
{
    public ObservableCollection<FlickrImage> FlickrImages { get; private set; }

    public MainPageViewModel()
    {
        FlickrImages = new ObservableCollection<FlickrImage>();
    }

    public async void Load()
    {
        var request = HttpWebRequest.CreateHttp("http://api.flickr.com/services/feeds/photos_public.gne?format=xml&tags=wp7");
        var resp = await request.GetResponseAsync();

        using (var strm = resp.GetResponseStream())
        {
            var xml = XElement.Load(strm);

            var ns = XNamespace.Get("http://www.w3.org/2005/Atom");


            var images = (from entry in xml.Descendants(ns.GetName("entry"))
                            let title = entry.Element(ns.GetName("title"))

                            from links in entry.Descendants(ns.GetName("link"))
                            let rel=links.Attribute("rel")
                            where rel.Value == "enclosure"

                            let href = links.Attribute("href")
                            select new FlickrImage
                                        {
                                            ImageUrl = href.Value,
                                            Title = title.Value
                                        }).ToArray();

            foreach (var img in images)
            {
                FlickrImages.Add(img);
            }
        }
    }

    public class FlickrImage
    {
        public string ImageUrl { get; set; }
        public string Title { get; set; }
    }
}

About the Author

Nick Randolph runs Built to Roam, a consulting company that specializes in training, mentoring and assisting other companies build mobile applications. With a heritage in rich client applications for both the desktop and a variety of mobile platforms, Nick currently presents, writes and educates on the Windows Phone platform.

comments powered by Disqus

Featured

  • Creating a Progressive Web App with Blazor WebAssembly

    Not surprisingly, it's dead easy to create an app in Blazor that runs outside of the browser window and (potentially) in an offline mode. Before you get carried away, though, there are some key design decisions to make.

  • GitLab Takes Over VS Code Extension, Plans Improvements

    DevOps specialist GitLab has officially taken over the control of a GitLab extension for Microsoft's open source, cross-platform Visual Studio Code editor.

  • VS Code Python Tool Now Does Native Notebooks

    The Python Extension for VS Code Insiders team is previewing the newest implementation of notebooks, used frequently in data science with offerings such as Jupyter Notebooks.

  • As .NET 5 Nears, Content/Documentation Reorganization Starts

    A GitHub project is seeking to reorganize documentation and developer content in advance of the November debut of .NET 5, a unification of all things .NET that combines. .NET Core and other components.

  • Windows Devs Get Cross-Platform Page, Issues Repo

    Developers doing their coding on the Windows OS have received two new resource gifts from Microsoft: a new landing page for those using cross-platform technologies and a new GitHub repo with which to report issues to Windows engineering teams.Developers doing their coding on the Windows OS have received two new resource gifts from Microsoft: a new landing page for those using cross-platform technologies and a new GitHub repo with which to report issues to Windows engineering teams.

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.

Upcoming Events