2016-09-30 34 views
2

我正在使用圖像列表框,它增加了內存使用高達千兆字節。我使用這個xaml。WPF listbox與圖像inreasing內存

<Grid Grid.Row="0" Grid.Column="1"> 
      <ScrollViewer> 
       <ListBox ItemsSource="{Binding Path=FilterImportSlideCollection}" ItemTemplate="{StaticResource slideItemTemplate}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" /> 
      </ScrollViewer> 
     </Grid> 

而且模板是

<DataTemplate x:Key="slideItemTemplate" > 
    <Grid Width="100" Height="130" Margin="2 2 2 2" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="80"/> 
      <RowDefinition/> 
     </Grid.RowDefinitions> 
     <Border Background="White" BorderBrush="Black" BorderThickness="1" Grid.Row="0" Panel.ZIndex="3" Canvas.Left="0" Canvas.Right="0"> 
      <Image MinWidth="100" MinHeight="80" HorizontalAlignment="Center" Source="{Binding ImagePath, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"></Image> 
      </Border> 
     <TextBlock HorizontalAlignment="Left" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Text="{Binding Title}" Foreground="Black"/> 
    </Grid> 
</DataTemplate> 

每個ImagePath的具有圖像的像 「https://localhost:2673/SlideThumbnail/1272.png

+0

首先,把你的照片在本地文件夾。 – Coding4Fun

+0

它可能會在第一次嘗試,但如果我在服務器上添加一些圖像圖像後多次打開列表框,我將需要重新下載本地目錄中的所有圖像。 –

+0

我試過了你的建議,但沒有奏效。 –

回答

1

放置ListBox一個ScrollViewer內的路徑禁用UI虛擬化意味着所有的ListItems是立刻在內存中創建。

嘗試:

<Grid Grid.Row="0" Grid.Column="1"> 
    <ListBox ItemsSource="{Binding Path=FilterImportSlideCollection}" ItemTemplate="{StaticResource slideItemTemplate}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" /> 
</Grid> 

有關虛擬化的更多信息,看看MSDN:

第一的

Displaying Large Data Sets