Luiz Negrini
Luiz Negrini

Reputation: 666

ObservableCollection with binding in c# Windows Phone

How to make this list binding with listbox? I can get the data I want, because when I put a breakpoint I see that is being loaded correctly. I heard that they have a ObservableCollection but do not know how to use and then do not bind with the xaml.

 private void DownLoadCompleted(object sender, HtmlDocumentLoadCompleted e)
        {
            _popVideos = new List<PopularVideos>();
            var data = e.Document.DocumentNode.SelectSingleNode("//div[@class='content']")
               .Descendants("img")
               .Select(img => new
               {
                   Title = img.Attributes["alt"].Value,
                   Url = img.Attributes["src"].Value,
               }).ToList();

            foreach (var item in data)
            {               
                PopularVideos pop = new PopularVideos(item.Title, item.Url);
                _popVideos.Add(new PopularVideos(item.Title, item.Url));
            }

            listBoxPopular.ItemsSource = _popVideos;
        }

My class:

class PopularVideos
    {
        public PopularVideos() { }
        public PopularVideos(string titulo, string url)
        {
            Titulo = titulo;            
            BitmapImage Img = new BitmapImage(new Uri(url));
        }

        public string Titulo { get; set; }

        public Uri Url { get; set; }
    }

Upvotes: 0

Views: 1332

Answers (1)

Den
Den

Reputation: 16826

As I mentioned in your original question, there is a great article that you should go through as an intro to data binding.

Upvotes: 1

Related Questions