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>
, 그것은 웁니다을 동시에 모든 이름 + 이미지 ... 목록 상자를 참기 힘들게 느리게 만듭니다. 사전에
덕분에