0

このリストをリストボックスにバインドするにはどうすればよいですか? ブレークポイントを配置すると、正しくロードされていることがわかるため、必要なデータを取得できます。彼らは ObservableCollection を持っていると聞きましたが、使い方がわからず、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;
        }

私のクラス:

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; }
    }
4

1 に答える 1

1

元の質問で述べたように、データ バインディングの概要として読むべき優れた記事があります。

于 2013-07-06T02:30:38.193 に答える