2011-08-22 7 views
0

동적으로 채워지는 자동 완성 기능을 수행하는 목록 상자가 있습니다. 목록 상자에는 직원의 그림이있는 이름 목록이 표시됩니다. 나는 느린 이미지로 데이터를 채우는 것을 발견했다.WPF ListBox Aynchronous Binding

이름을 먼저 채우고받은대로 비동기 적으로 데이터를 업로드 할 수 있기를 원합니다. 그렇게하려면 어떻게해야합니까?

순간에 내 이미지 클래스 코드 :

public class Img : INotifyPropertyChanged 
{ 
    private string name; 
    private Image image; 
    public event PropertyChangedEventHandler PropertyChanged; 

    public Img(string name, Image image) 
    { 
     this.name = name; 
     this.image = image; 
    } 

    public string Name 
    { 
     get { return name; } 
     set 
     { 
      name = value; 
      OnPropertyChanged("PersonName"); 
     } 
    } 

    public Image Image 
    { 
     get { return image; } 
     set 
     { 
      image = value; 
      OnPropertyChanged("Image"); 
     } 
    } 

    // Create the OnPropertyChanged method to raise the event 
    protected void OnPropertyChanged(string name) 
    { 
     PropertyChangedEventHandler handler = PropertyChanged; 
     if (handler != null) 
     { 
      handler(this, new PropertyChangedEventArgs(name)); 
     } 
    } 
} 

데이터를 채 웁니다 코드 :

 foreach (KeyValuePair<string, string> entry in items) 
     { 
      System.Windows.Controls.Image webImage = new System.Windows.Controls.Image(); 
      webImage.Dispatcher.Invoke(DispatcherPriority.Normal, 
       (ThreadStart)delegate 
       { 

        BitmapImage image = new BitmapImage(); 
        image.BeginInit(); 
        image.UriSource = new Uri(//Where the source is); 
        image.EndInit(); 

        webImage.Source = image; 
       }); 
      myListBox.Items.Add(new Img(entry.Value, webImage)); 
     } 

내 XAML 코드 : 순간

<Popup Name="myPopUp"> 
    <ListBox Name="myListBox" FontSize="14"> 
     <ListBox.ItemTemplate> 
      <DataTemplate DataType="{x:Type local:Img}"> 
       <StackPanel Orientation="Horizontal"> 
        <ContentPresenter Margin="3" Content="{Binding Image, IsAsync=True}"/> 
        <TextBlock Margin="3" Text="{Binding Name, IsAsync=True}"/> 
       </StackPanel> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
</Popup> 

, 그것은 웁니다을 동시에 모든 이름 + 이미지 ... 목록 상자를 참기 힘들게 느리게 만듭니다. 사전에

덕분에

답변

0

은 확인을 작동하려면 이미지의 게으른 로딩 누락 두 가지 ....

  1. 느린 로딩의 순서로 PriorityBinding하고 빠른 로딩 imagesources이 있습니다.
  2. DownloadCompleted 각 이미지의 이벤트는 표시 할 준비가 된 바인딩의 변경 사항을 알려야합니다.

initial image in WPF Image Control

How to lazy load image byte[] into a WPF image control?

이 도움이되는지 알려주세요 ...이 두 게시물을 참조하고 힌트를 얻을 수 있는지 확인합니다.