你好,我从网上获取信息,并将其添加到绑定在列表框中的ObservableCollection中,有时此信息太多,我的程序必须等到收到所有信息后再更新接口 如何显示同时添加的信息?
我的ObservableCollection类型为INotifyPropertyChanged
XAML
<ListBox ItemsSource="{Binding ItemResult}">
C#
private ObservableCollection<ItemResultModel> _ItemResult;
public ObservableCollection<ItemResultModel> ItemResult
{
get => _ItemResult;
set
{
if (_ItemResult != value)
{
_ItemResult = value;
NotifyPropertyChanged("ItemResult");
}
}
}
ItemResult = new ObservableCollection<ItemResultModel>();
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(url);
HtmlNode img = doc.DocumentNode.SelectSingleNode("//div[@class='poster']//img");
if (img != null)
{
poster.Source = bitmap;
}
var repeater = doc.DocumentNode.SelectNodes("//ul[@class='scrolllist']");
if (repeater != null)
{
foreach ((HtmlNode node, int index) in repeater.WithIndex())
{
string translator = node.SelectNodes("//div[@class='comment-col']")[index].InnerText;
string download_Link = node.SelectNodes("//a[@class='download icon-download']")[index].GetAttributeValue("href", "");
ItemResultModel item = new ItemResultModel { Name = node.InnerText, Translator = singleLineTranslator, Link = download_Link, Language = GlobalData.Config.SubtitleLang };
ItemResult.Add(item);
}
}