WP7 Toolkit Update Removed GetItemsInView() from the LongListSelector

后端 未结 3 899
粉色の甜心
粉色の甜心 2021-01-12 19:29

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 suppor

3条回答
  •  春和景丽
    2021-01-12 20:16

    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 trackedItems = new List();
    
    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());
    }
    

    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.

提交回复
热议问题