gpt4 book ai didi

c# - Windows Phone 7 异步添加项目到堆栈面板

转载 作者:太空宇宙 更新时间:2023-11-03 20:26:29 25 4
gpt4 key购买 nike

我想知道是否可以将子项异步添加到堆栈面板(或任何其他元素)。似乎所有项目都是一次渲染的。

无论我使用后台工作程序还是调度程序都没有关系。结果总是一样的——当所有项目都被添加后,它们就会显示出来。

我想要的是这样的:

Deployment.Current.Dispatcher.BeginInvoke(() => {
foreach (var item in items.Skip(x).Take(pageSize))
{
// when this row is executed new item should be visible
ItemsList.Children.Add(new _ListItem(item));
}
});

问候最大

最佳答案

此代码段每 500 毫秒将新的 TextBlock 添加到 stackPanel 中,而不会卡住 UI。项目在添加后立即在 UI 中可见:

ThreadPool.QueueUserWorkItem(_ => {
foreach (int item in Enumerable.Range(1,50)) {
Thread.Sleep(500);//simulate some calculations here
int item1 = item;
Deployment.Current.Dispatcher.BeginInvoke(() => {
stackPanel.Children.Add(new TextBlock(){Text = "Text "+item1});
});
}
});

关于c# - Windows Phone 7 异步添加项目到堆栈面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10375967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com