1
我正在嘗試爲Windows Phone創建一個應用程序,該應用程序需要顯示聯繫人列表,如人員中心中所示。聯繫圖片加載時間太長
這是用於顯示聯繫人的xaml。
<toolkit:LongListMultiSelector x:Name="ContactList" IsGroupingEnabled="True" HideEmptyGroups="True">
<toolkit:LongListMultiSelector.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Border BorderThickness="2" HorizontalAlignment="Left" BorderBrush="{StaticResource PhoneAccentBrush}" >
<Image Source=" {Binding Converter={StaticResource ContactPictureConverter}}" Width="48" Height="48" Stretch="Fill" />
</Border>
<TextBlock Text="{Binding Path=DisplayName, Mode=OneWay}" />
</StackPanel>
</DataTemplate>
</toolkit:LongListMultiSelector.ItemTemplate>
</toolkit:LongListMultiSelector>
這是ContactPicureConverter
public class ContactPictureConverter : System.Windows.Data.IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Contact c = value as Contact;
if (c == null) return null;
System.IO.Stream imageStream = c.GetPicture();
if (null != imageStream)
{
return Microsoft.Phone.PictureDecoder.DecodeJpeg(imageStream);
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
此外,我分配在構造函數中的聯繫人作爲跟隨
public ContactListPage()
{
InitializeComponent();
Contacts cons = new Contacts();
cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>((sender,e)=>{ContactList.DataContext=e.Results;});
cons.SearchAsync(String.Empty, FilterKind.None, "bla");
}
但是當我打開這個頁面,聯繫人需要很長時間才能加載。但是,當我在人員中心打開相同的聯繫人列表時,其加載速度要快得多。 那麼我能做些什麼來使聯繫人立即加載。