Performance UI在JumpListSelector(WP8)中显示用户联系人列表花费了很长时间-这次如何改进?
我正在开发一个WP8应用程序,我正在尝试使用LongListSelector(作为People应用程序)在跳转列表中显示所有用户联系人 它工作得很好,但是根据联系人的数量,用户界面显示联系人需要很长时间 我是这样做的: XAML:Performance UI在JumpListSelector(WP8)中显示用户联系人列表花费了很长时间-这次如何改进?,performance,windows-phone-8,Performance,Windows Phone 8,我正在开发一个WP8应用程序,我正在尝试使用LongListSelector(作为People应用程序)在跳转列表中显示所有用户联系人 它工作得很好,但是根据联系人的数量,用户界面显示联系人需要很长时间 我是这样做的: XAML: 关于代码: private void Contacts_SearchContactsCompleted(object sender, ContactsSearchEventArgs e) { Stopwatch stopwatch = Stopwatch.
关于代码:
private void Contacts_SearchContactsCompleted(object sender, ContactsSearchEventArgs e)
{
Stopwatch stopwatch = Stopwatch.StartNew();
IList<Contact> contacList = e.Results.Where(m => m.PhoneNumbers.Count() > 0).ToList();
cdList = new List<ContactData>();
foreach(Contact c in contacList)
{
BitmapImage img = new BitmapImage();
img.DecodePixelHeight = 62;
img.DecodePixelWidth = 62;
img.UriSource = null;
bool tam = c.GetPicture() == null;
if (!tam)
img.SetSource(c.GetPicture());
foreach (ContactPhoneNumber cpn in c.PhoneNumbers)
{
ContactData cd = new ContactData();
cd.Name = c.DisplayName;
cd.Image = img;
cdList.Add(cd);
}
}
List<AlphaKeyGroup<ContactData>> DataSource = AlphaKeyGroup<ContactData>.CreateGroups(cdList,
System.Threading.Thread.CurrentThread.CurrentUICulture,
(ContactData s) => { return s.Name; }, true);
AddrBook.ItemsSource = DataSource;
cdListFiltred = cdList;
stopwatch.Stop();
System.Diagnostics.Debug.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
}
private void Contacts\u search Contacts已完成(对象发送者、联系人搜索目标)
{
秒表秒表=Stopwatch.StartNew();
IList contacList=e.Results.Where(m=>m.PhoneNumbers.Count()>0.ToList();
cdList=新列表();
foreach(联系人列表中的c)
{
BitmapImage img=新的BitmapImage();
img.DecodePixelHeight=62;
img.DecodePixelWidth=62;
img.UriSource=null;
bool tam=c.GetPicture()==null;
如果(!tam)
img.SetSource(c.GetPicture());
foreach(c.PhoneNumber中的ContactPhoneNumber cpn)
{
ContactData cd=新的ContactData();
cd.Name=c.DisplayName;
cd.Image=img;
cdList.Add(cd);
}
}
列表问题在于XAML。当数据量很大时,性能会很差。您可以使用虚拟化来提高性能,在虚拟化longlistselector上快速搜索google应该会得到结果。我建议对大量数据使用Telerik控件,因为控件本身就是虚拟化的
private void Contacts_SearchContactsCompleted(object sender, ContactsSearchEventArgs e)
{
Stopwatch stopwatch = Stopwatch.StartNew();
IList<Contact> contacList = e.Results.Where(m => m.PhoneNumbers.Count() > 0).ToList();
cdList = new List<ContactData>();
foreach(Contact c in contacList)
{
BitmapImage img = new BitmapImage();
img.DecodePixelHeight = 62;
img.DecodePixelWidth = 62;
img.UriSource = null;
bool tam = c.GetPicture() == null;
if (!tam)
img.SetSource(c.GetPicture());
foreach (ContactPhoneNumber cpn in c.PhoneNumbers)
{
ContactData cd = new ContactData();
cd.Name = c.DisplayName;
cd.Image = img;
cdList.Add(cd);
}
}
List<AlphaKeyGroup<ContactData>> DataSource = AlphaKeyGroup<ContactData>.CreateGroups(cdList,
System.Threading.Thread.CurrentThread.CurrentUICulture,
(ContactData s) => { return s.Name; }, true);
AddrBook.ItemsSource = DataSource;
cdListFiltred = cdList;
stopwatch.Stop();
System.Diagnostics.Debug.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
}