WP7 工具包更新从 LongListSelector 中删除了 GetItemsInView() [英] WP7 Toolkit Update Removed GetItemsInView() from the LongListSelector

查看:14
本文介绍了WP7 工具包更新从 LongListSelector 中删除了 GetItemsInView()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过对 Windows Phone 工具包的最新更新,他们为 Mango 版本彻底检查了 LongListSelector 的内部结构.其中一项更改是取消了对 GetItemsInView() 函数的支持(它现在返回一个空列表).此函数以前返回当前在屏幕上可见的项目列表.当我离开页面时,我使用它来获取对最顶层可见项的引用,以便我可以使用 ScrollTo(object item) 支持墓碑后的恢复.

With the latest update to the Windows Phone Toolkit they have overhauled the internals of the LongListSelector for the Mango release. One of the changes was removing support for the GetItemsInView() function (it now returns an empty list). This function previously returned a list of items that were currently visible on the screen. I was using this to get a reference to the topmost visible item when navigating away from a page so that I could support recovery after a tombstone by using ScrollTo(object item).

有谁知道建议的替代方案是什么?我知道 Mango 墓碑不是一个问题,但我仍然想支持它,并且可能还有其他一些我想回忆滚动位置的场景.在某些情况下,我的列表包含数千个项目.

Does anyone know what the suggested alternative would be? I know that with Mango tombstoning is much less of an issue, but I'd still like to support it and there may be some other scenarios where I'd want to recall the scroll position. My list has thousands of items in some cases.

推荐答案

据我所知,你必须订阅 LLS 的 LinkUnlink 事件.Link 将传入一个 arg,其中包含添加到 LLS 可见部分的项目.Unlink 对从 LLS 中删除的那些项目执行相同的操作.所以你会做这样的事情:

From what I can tell from the new bits, you have to subscribe to the LLS's Link and Unlink events. Link will pass in an arg that contains the item added to the visible part of the LLS. Unlink does the same for those items removed from the LLS. So you'd do something like this:

List<string> trackedItems = new List<string>();

private void myListOfStrings_Link(object sender, LinkUnlinkEventArgs e)
{
    var x = e.ContentPresenter;
    if (x == null || x.Content == null)
        return;
    trackedItems.Add(x.Content.ToString());
}

private void myListOfString_Unlink(object sender, LinkUnlinkEventArgs e)
{
    var x = e.ContentPresenter;
    if (x == null || x.Content == null)
        return;
    trackedItems.Remove(x.Content.ToString());
}

请注意,LinkUnlink 将针对底层列表中的每个渲染项目触发,因此如果您使用 LLS 的分组功能,那么您将必须根据实际返回的类型来增加关于是否跟踪项目的测试.因此,如果您有某种要跟踪其底层对象的组对象,您可以执行以下操作:

Note that Link and Unlink will fire for EVERY rendered item in the underlying list, so if you're using the grouping features of the LLS, then you'll have to augment your test on whether or not to track the item based on what type is actually coming back. So if you have some sort of group object for which you want to track the underrlying objects, you might do something like this:

private void myGroupedListOfObjects_Link(object sender, LinkUnlinkEventArgs e)
{
    var x = e.ContentPresenter;
    if (x == null || x.Content == null)
        return;
    var myObject = x.Content as MyObject;
    if (myObject != null)
    {
        foreach (var item in myObject.Items)
        {
            trackedItems.Add(item);
        }
    }
}

我希望这会有所帮助!如果成功,请告诉我们.

I hope this helps! Let us know if it works out.

这篇关于WP7 工具包更新从 LongListSelector 中删除了 GetItemsInView()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆