0

我想知道是否有人知道在手机应用程序上设置属性或设置的方法,以便 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>

我不能使用列表框或类似的东西,因为图像在我的应用程序中并没有很好地排列。

有什么建议么?谢谢!托马斯

4

1 回答 1

0

使图像不可见并不能阻止它被解码成未压缩的形式,这会占用大量内存,尤其是在它很大的情况下。

您将需要一种更有效的“虚拟化”图像的方法,以便在图像不在视野范围内时完全卸载它们。这就是 LongListSelector 可以给你的。ScrollViewer 不这样做。

于 2013-03-29T07:19:55.490 回答