2013-03-28 68 views
0

我想知道是否有人知道在手機應用程序上設置屬性或設置的方法,以便ScrollViewer使用較少的內存緩存。我目前有一個應用程序,可以在屏幕上顯示圖像,甚至可以使用一種算法確保只有靠近或與屏幕相交的圖像可見,但偶爾我偶爾會遇到內存不足的情況附近的圖像。Windows Phone 8中ScrollViewer的內存使用情況

舉個例子,下面的XAML會在300個空間中吃掉125MB,而這只是空白的白色畫布。

<phone:PhoneApplicationPage 
x:Class="DemoScroller.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
FontFamily="{StaticResource PhoneFontFamilyNormal}" 
FontSize="{StaticResource PhoneFontSizeNormal}" 
Foreground="{StaticResource PhoneForegroundBrush}" 
SupportedOrientations="Portrait" Orientation="Portrait" 
shell:SystemTray.IsVisible="True"> 

<!--LayoutRoot is the root grid where all page content is placed--> 
<Grid x:Name="LayoutRoot" Background="Transparent"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 

    <!--TitlePanel contains the name of the application and page title--> 
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> 
     <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/> 
     <TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> 
    </StackPanel> 

    <!--ContentPanel - place additional content here--> 
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
     <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> 
      <Canvas Width="2000" Height="8000"> 
       <Canvas Width="990" Height="1990" Background="White"/> 
       <Canvas Width="990" Height="1990" Canvas.Left="1010" Background="White"/> 
       <Canvas Width="990" Height="1990" Canvas.Top="2000" Background="White"/> 
       <Canvas Width="990" Height="1990" Canvas.Left="1010" Canvas.Top="2000" Background="White"/> 
       <Canvas Width="990" Height="1990" Canvas.Top="4000" Background="White"/> 
       <Canvas Width="990" Height="1990" Canvas.Left="1010" Canvas.Top="4000" Background="White"/> 
      </Canvas> 
     </ScrollViewer> 
    </Grid> 
</Grid> 

</phone:PhoneApplicationPage> 

我不能使用列表框或類似的東西,因爲圖像並不真的排隊在我的應用程序中很好地排隊。

有什麼建議嗎? 謝謝! Tomas

回答

0

使圖像不可見並不會停止將其解碼爲未壓縮的形式,這會佔用大量的內存,尤其是如果它很大。

您需要一種更有效的方式來「虛擬化」圖像,以便在圖像不可見時完全卸載圖像。這就是LongListSelector可以給你的。 ScrollViewer不會這樣做。

+0

即使圖像佔用空間,當它們的可見性設置爲摺疊時,這是花生相比,實際顯示它們時ScrollViewer會吃什麼。即使我用一個空白的矩形替換並丟棄了我的應用程序中的每個圖像,它仍然會非常快地耗盡內存。 – Tomas