Coverflow内存不足

时间:2014-06-11 10:48:45

标签: c# silverlight windows-phone-8 windows-phone out-of-memory

我正在使用Windows 8 Phone Application。

我有问题,我在图像上面逐一加载图像。它叫做coverflow功能。

我正在Out of memory exception

for (int j = 0; j < items.Count; j++)
            {
                for (int i = 0; i < items.Collection.Count; i++)
                {
                    Myobj obj = items[j].Collection[i];
                    if (obj.correct == 1)
                    {
                        coverflow.Add(new CoverFlow(items[j].Text, answer.TextTwo));
                    }
                }
            }

            CarouselList.ItemsSource = coverflow;

DataTemplate:

<DataTemplate x:Key="DataTemplate1">
            <Grid VerticalAlignment="Center" HorizontalAlignment="Center">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Border Grid.Row="0" Height="400" Width="400" CornerRadius="30,30,30,30">
                    <Border.Background>
                        <ImageBrush ImageSource="Images/sample.png" />
                    </Border.Background>
                </Border>
                <Grid Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Top">
                    <TextBlock HorizontalAlignment="Center" 
                               VerticalAlignment="Center"
                               Margin="5,20,5,5"
                               Foreground="#000000"
                               Text="{Binding Title}"/>
                </Grid>
                <Grid Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Bottom">
                <TextBlock HorizontalAlignment="Center" 
                               VerticalAlignment="Center"
                               Margin="5,5,5,20"
                               Foreground="#000000"
                               Text="{Binding SubTitle}"/>
                </Grid>
            </Grid>
        </DataTemplate>

这里有大约300多件物品一个接一个地展示:

像这样:

enter image description here

它根本不起作用我试图减少widht and height from 400 to 200它的工作原理,但我希望图像大小为400,这样看起来不错。

即使我的图像是400 * 400

,我怎么能避免这种内存不足

1 个答案:

答案 0 :(得分:1)

这真的是我的头脑。 Haven暂时没有解决这个问题。

1.自己写一个能给你带来一堆物品的功能

public List<Item> GetFirstItems()
{
    return items.Collection.Take(50);
}

public Item GetOtherItems(int skip)
{ 
     return items.Collection.Skip(skip).Take(25)
}

2.挂机到SelectionChangedEvent进行控制

//keep this somewhere so you know where you are in the list
var currentBatch = 0;

private void SelectionChanged(sender object, ChangedEventArgs e)
{
     var position = e.CurrentItemIndex % 25;

     if(position > currentBatch)
     {
          currentBatch = position;
          var newItems = GetOtherItems(currentBatch * 25);

          //take the global list of items and modify it;
          //because we are moving right we only need the last 25 so we
          //can skip the first 25
          coverflow= coverflow.Skip(25);

          //add your new items
          coverflow.AddRange(newItems);
          CarouselList.ItemsSource = coverflow; // you will have to clear the source first
     }
     else if(position < currentBatch)
     {
          currentBatch = position;
          var newItems = GetOtherItems(currentBatch * 25);

          //take the global list of items and modify it;
          //because we are moving left we only need the first 25 so we
          //can take the first 25
          coverflow= coverflow.Take(25);

          //add your new items
          newItems.AddRange(coverflow);
          coverflow = newItems;
          CarouselList.ItemsSource = coverflow; // you will have to clear the source first
     }
}

您需要注意的另一件事是记住哪个是当前项目并再次将其设置为当前项目。

这一切都是从头脑中写出来的,我不知道它是否与你的控件配合使用,但我希望它至少会对你有所帮助:)