2011-12-21 63 views
0

我有一個包含大約50個條目的列表框。每個條目有3張圖片和文本爲列表框中的項目創建視圖非常緩慢

它看起來是這樣的

<grid> 
    <TextBlock x:Name="textBlock" Text="{Binding Title}" Foreground="{Binding Brush}" Grid.Column="1" Margin="8,43,-256,8" FontSize="26.667" FontFamily="Segoe WP" TextWrapping="Wrap" RenderTransformOrigin="0.5,0.5" TextTrimming="WordEllipsis" Width="248" Height="90" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
    <Image x:Name="image2" Source="{Binding Picture3}" Margin="48,8,29,33" RenderTransformOrigin="0.5,0.5" Width="100" Height="100" VerticalAlignment="Center" HorizontalAlignment="Center" /> 
    <Image x:Name="image" Source="{Binding Picture2}" Margin="58,16,18,24" RenderTransformOrigin="0.5,0.5" Width="100" Height="100" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
    <Image x:Name="image1" Source="{Binding Picture1}" Margin="69,25,8,16" RenderTransformOrigin="0.5,0.5" Width="100" Height="100" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
</grid> 

的問題是,如果我啓動應用程序,並滾動到結束,大約需要5-10秒,以顯示enries 。更糟糕的是,如果我再次向上滾動,也會發生同樣的情況。 如果我在BackgroundWorker Thread中下載導致UI有時會凍結秒的文件,此行爲會變得更糟。

BackgroundWorker線程如何影響UI? 在使用列表框時,我應該特別注意些什麼?

編輯:

Picture屬性是怎樣的一個黑客以創建圖片

private BitmapImage m_mediumCoverArt = null; 

public BitmapImage MediumCoverWithoutDownload 
{ 
    get 
    { 
     if (m_mediumCoverArt == null) 
     { 
      try 
      { 
       using (IsolatedStorageFile isoStore = 
       IsolatedStorageFile.GetUserStoreForApplication()) 
       { 
        if (!isoStore.FileExists(GlobalVariables.BEAT_COVER_FOLDER + "/" + GetPath.ForCoverArt(this.m_pictureURL + GlobalVariables.MEDIUM_IMAGE_POSTFIX))) 
         return null; 

        using (IsolatedStorageFileStream isoStream = 
         new IsolatedStorageFileStream(GlobalVariables.BEAT_COVER_FOLDER + "/" + GetPath.ForCoverArt(this.m_pictureURL + GlobalVariables.MEDIUM_IMAGE_POSTFIX), 
          FileMode.Open, isoStore)) 
        { 
         m_mediumCoverArt = new BitmapImage(); 
         m_mediumCoverArt.SetSource(isoStream); 
         return m_mediumCoverArt; 
        } 
       } 
      } 
      catch (Exception) 
      { 
       return null; 
      } 
     } 
     else 
     { 
      return m_mediumCoverArt; 
     } 
    } 
} 

我知道圖片的加載在UI線程中運行的工作數據綁定的,但它需要只有幾毫秒,它也只發生一次。所以即使這可以解釋第一次裝貨的時間長了,它應該能夠在沒有問題的情況下繼續工作。

回答

1

什麼是Picture*屬性?這是一個外部資源的網址?默認情況下,圖像解碼在UI線程上執行。

瞭解更多關於圖像創建選項Off-thread decoding of images on Mango。也許它對你有幫助。

+0

我在Picture屬性中添加了更多描述。我會看看脫機影像 – Philiiiiiipp 2011-12-21 19:18:02