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