1

我有更多然後1000圖像(拇指),需要在的JumpList向他們展示的Windows Phone裝入大量的圖像從IsolatedStorage在IsolatedStorage的JumpList

我有一個XAML代碼:

<telerikData:RadJumpList telerikCore:InteractionEffectManager.IsInteractionEnabled="True" Name="TitleCollection" ItemsSource="{Binding TitleCollection}"> 
<telerikData:RadJumpList.ItemTemplate > 
<DataTemplate> 
    <StackPanel Orientation="Horizontal">          
     <Image Source= "{Binding Cover}" CacheMode="BitmapCache" /> 
     <TextBlock Text="{Binding FirstLine}" />           
    <StackPanel> 
</DataTemplate> 

和型號

public class TitleList : ViewModelBase 
{  
    public String Id_on_server { get; set; } 

    public String FirstLine 
    { 
     get;set;   
    } 

    private static Mutex _mut = new Mutex(false,"mutex control"); 

    BitmapImage _Cover; 

    public BitmapImage Cover 
    { 
     get 
     {    
      if (_Cover == null) 
      { 
       BackgroundWorker bw = new BackgroundWorker(); 
       bw.DoWork += new DoWorkEventHandler(
        (object sender, DoWorkEventArgs e) => 
        { 
         String fileName = App.ImageDirectory + "/" + this.Id_on_server + "_front_thumb.jpg"; 
         Deployment.Current.Dispatcher.BeginInvoke(delegate() 
         { 
          using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) 
          { 
           if (myIsolatedStorage.FileExists(fileName)) 
           { 
            try 
            { 
             _Cover = new BitmapImage(); 
             _Cover.SetSource(myIsolatedStorage.OpenFile(fileName, FileMode.Open, FileAccess.Read)); 
            } 
            catch (Exception ex) 
            { 
             System.Diagnostics.Debug.WriteLine(ex.Message); 
            } 
           } 
           else 
           { 
            _Cover = new BitmapImage(); 
            _Cover.UriSource = new System.Uri("/Image/Movie.Icon.Default.png", System.UriKind.Relative);          
           } 
          } 
         }); 
        }); 

       bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
        (object sender, RunWorkerCompletedEventArgs e) => 
        { 
         _mut.ReleaseMutex(); 
         Deployment.Current.Dispatcher.BeginInvoke(delegate() 
         { 
          RaisePropertyChanged("Cover"); 
         }); 
        } 
        ); 

       _mut.WaitOne(); 
       bw.RunWorkerAsync(); 
      } 

      return _Cover; 
     } 
     set 
     { 
      _Cover = value; 
      RaisePropertyChanged("Cover"); 
     } 
    } 
} 

因此,我從背景中的孤立存儲中獲取圖像並顯示在列表中。 此代碼有效,但如果JumpList快速滾動顯示項目的強烈延遲發生。

任何人都可以建議如何正確顯示大量的圖片或製作像LowProfileImageLoader一樣的LoadDelay。 任何建議或示例都會有所幫助。

回答

1

在我的項目中,我使用Kawagoe Toolkit進行類似的任務。

在代碼中,只有1行代碼的在後臺線程中執行:

String fileName = App.ImageDirectory + "/" + this.Id_on_server + "_front_thumb.jpg"; 

您的代碼的其餘部分,包括I/O,則在UI線程中執行的文件,它是錯誤。一種修復方法:

public class TitleList : ViewModelBase 
{ 
    public String Id_on_server { get; set; } 

    BitmapImage _Cover; 

    static MemoryStream readImage(string id) 
    { 
     String fileName = Path.Combine(App.ImageDirectory, this.Id_on_server + "_front_thumb.jpg"); 
     using(IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      if(!myIsolatedStorage.FileExists(fileName)) 
       return null; 
      try 
      { 
       using(var stm = myIsolatedStorage.OpenFile(fileName, FileMode.Open, FileAccess.Read)) 
       { 
        var ms = new MemoryStream(); 
        stm.CopyTo(ms); 
        return ms; 
       } 
      } 
      catch(Exception ex) 
      { 
       System.Diagnostics.Debug.WriteLine(ex.Message); 
      } 
      return null; 
     } 
    } 

    public BitmapImage Cover 
    { 
     get 
     { 
      if(null != _Cover) 
       return _Cover; 

      ThreadPool.QueueUserWorkItem(s => 
      { 
       var ms = readImage(Id_on_server); 
       Deployment.Current.Dispatcher.BeginInvoke(() => 
       { 
        var img = new BitmapImage(); 
        if(null == ms) 
         img.UriSource = new Uri("/Image/Movie.Icon.Default.png", System.UriKind.Relative); 
        else 
         img.SetSource(ms); 
        _Cover = img; 
        RaisePropertyChanged("Cover"); 
       }); 
      }); 
      return null; 
     } 
    } 
} 
+0

謝謝你!這真的幫助我。 – Vovich 2013-02-15 07:31:24

+0

爲什麼Wp7.5上的文件讀取速度太慢?當我滾動列表中的500個項目時,我等待了很長時間,而圖像完整顯示。你知道有什麼可能停止加載屏幕以外的圖像。所以如果我滾動到500,它不會開始加載1-490,但在滾動期間,取消這些,並更快地顯示我在屏幕上看到的490-500。 – Vovich 2013-02-15 12:54:08

相關問題