内存不足 - 在PivotControl中有15个以上的PivotItem

时间:2014-07-09 20:07:11

标签: windows-phone-8 out-of-memory

我有一个数据透视控件,其ItemsSource可以数据绑定到一组项目。

该集合最多可包含50个项目,因此这意味着它最多可以包含50个PivotItems。 每个PivotItem都包含图像控件和一些文本控件。

在枢轴页面(大约15)之间滑动后,按下后​​退按钮时,应用程序会因“内存不足”而崩溃。异常。

当然,问题出现在PivotItems中,每次刷到一个新内存时都会占用所有内存。

我知道guildlines不推荐使用超过6-7项的数据透视,但我真的需要这样。

我在网上看到一些建议使用ContentControl和内容绑定到我的项目布局作为资源...但我觉得很难实现。

如何获得理想结果(没有内存溢出)的更多建议?

谢谢!

编辑:

我试图仅通过3,当前,下一个和前一个来操纵项目。 但是枢轴的行为并不好。我应该如何增加/减少Pivot.SelectedIndex?

   private void GestureListener_Flick(object sender, FlickGestureEventArgs e)
    {
        if (e.Direction.ToString() == "Horizontal") //Left or right
        {
            var itemVM = this.DataContext as ItemViewModel;
            int i = pivot.SelectedIndex;

            ObservableCollection<Item> items = new ObservableCollection<Item>();
            var currentItemIndex = itemVM.CurrentReader.Reader.Items.IndexOf(itemVM.SelectedItem);

            if (e.HorizontalVelocity > 0) //Right
            {
                currentItemIndex++;
            }
            else //Left
            {
                currentItemIndex--;    
            }

            if (itemVM.AllItems.Count >= 3)
            {

                if (currentItemIndex == 0) // in case we are in the first item m in the AllItems collection.
                {
                    items.Add(itemVM.AllItems[itemVM.AllItems.Count - 1]);
                    items.Add(itemVM.AllItems[currentItemIndex]);
                    items.Add(itemVM.AllItems[currentItemIndex + 1]);
                }
                else if (currentItemIndex == itemVM.AllItems.Count - 1) // in case we are in the last item in the AllItems collection.
                {
                    items.Add(itemVM.AllItems[currentItemIndex - 1]);
                    items.Add(itemVM.AllItems[currentItemIndex]);
                    items.Add(itemVM.AllItems[0]);
                }
                else
                {
                    items.Add(itemVM.AllItems[currentItemIndex - 1]);
                    items.Add(itemVM.AllItems[currentItemIndex]);
                    items.Add(itemVM.AllItems[currentItemIndex + 1]);
                }
            }
            else // in case we have only 3 items, no manpulation needed.
            {
                items = itemVM.AllItems;
            }


            itemVM.CurrentItemsCollection = items; // only 3 items




        }


    }

0 个答案:

没有答案