1

我想在我的一个 Windows Phone 7 应用程序的全景页面中添加一个延迟加载列表框(滑动时加载内容)。但是,我可以使用数据透视页面来做到这一点。我提到了这个链接

但这不适用于全景页面。
谁能帮帮我吗?

4

2 回答 2

1

Have you looked at the Telerik Rad Controls yet? They have all types of pull to refresh controls. I used them in a recent app I released called "Rad Libs". You can see the controls here http://www.telerik.com/products/windows-phone.aspx and you can also download an app that demos all of their controls. (Disclaimer: I have no affiliation with telerik. I stand to gain nothing from promoting them here)

于 2013-05-08T14:47:06.683 回答
1

好的,您将需要做以下两件事之一:使用 BCL Async 包(基本上将异步任务等添加到 WP7)或使用后台工作程序。我强烈推荐 BCL Async 包,它很容易上 Nuget。

现在,在您的 ViewModel 中(您正在使用 MVVM,是吗?)它绑定的属性,让我们调用它Items应该返回ObservableCollection您需要的项目类型。现在,这就是魔法发生的地方。在该Get属性的 ter 中,返回一个新集合并使用任务来填充它。像这样的东西:

public ObservableCollection<object> Items
{
    get
    {
        ObservableCollection<object> retCollection = new ObservableCollection<object>();
        FillCollection(retCollection);
        return retCollection;
    }
}

public async void FillCollection(ObservableCollection<object> collectionToFill)
{
    Task.Factory.StartNew(() =>
    {
        foreach(object objectToAdd in collectionImGettingThisDataFrom)
        {
            // We do this using the Dispatcher to 
            // be sure to pop back into the UI thread.
            Deployment.Current.Dispatcher.BeginInvoke(
                () => collectionToFill.Add(objectToAdd));
        }
    }
}

因为 FillCollection 是异步的,所以 Get 方法将继续并返回当前集合。在另一个线程上,创建的任务将找到要添加的数据,然后将其推送到 UI 线程以将其添加到集合中。这样,您将能够仅在请求时延迟加载数据,而不会完全阻塞您的 UI 线程。如果事实证明它仍然使您的 UI 变慢,您可以添加以下行:

await TaskEx.Delay(25); // Some time in milliseconds. Too much and it will 
                        // take a long time to load the list,
                        // too little and it will still bog down your UI.

foreach块的末尾,但不在Dispatcher调用中。

快乐编码!

于 2013-05-09T22:45:18.437 回答