我正在使用 ContactPicker 类将 Windows 8 People App 集成到我的应用程序中。当点击一个按钮时,我会加载 People App。用户选择了一些朋友,我想在 ListView 中显示他们的姓名、图像和电子邮件地址。
我在显示名称和图像方面没有问题。它没有显示电子邮件地址,而是显示:System.Collections.Generic.List`1[System.String]任何解决方案?
IReadOnlyList<GetContactDetails> ConDetails;
public IReadOnlyList<GetContactDetails> ContactDetails
{
get { return ConDetails; }
set { ConDetails = value; }
}
List<GetContactDetails> Contact;
public List<GetContactDetails> SetContacts
{
get { return Contact; }
set { Contact = value; }
}
private async void Contacts_Click(object sender, RoutedEventArgs e)
{
SetContacts = new List<App1.GetContactDetails>();
var contactSelector = new Windows.ApplicationModel.Contacts.ContactPicker();
contactSelector.CommitButtonText = "Pick contact";
var SelectedContact = await contactSelector.PickMultipleContactsAsync();
foreach (var item in SelectedContact)
{
SetContacts.Add(new GetContactDetails(item));
}
ContactList.ItemsSource = SetContacts;
}
XAML:
<ListView x:Name="ContactList" ItemTemplate="{StaticResource contactTemplate}" HorizontalAlignment="Left" Height="271" VerticalAlignment="Top" Width="585"/>
<DataTemplate x:Key="contactTemplate">
<Grid Width="400" Height="200" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition Width="350"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="75"></RowDefinition>
<RowDefinition Height="75"></RowDefinition>
<RowDefinition Height="75"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Text="Name" FontSize="20" FontWeight="Bold"></TextBlock>
<TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding ContactName}" FontWeight="Bold"></TextBlock>
<TextBlock Grid.Column="0" Grid.Row="1" Text="Mail" FontSize="20" FontWeight="Bold"></TextBlock>
<TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding ContactEmails}" FontSize="10" FontWeight="Bold"></TextBlock>
<!--<Image Height="100" Width="100" Grid.Column="1" Grid.Row="1" Source="{Binding ContactImage}" HorizontalAlignment="Left" VerticalAlignment="Center"></Image>-->
</Grid>
</DataTemplate>
GetContactDetails 类:
public class GetContactDetails
{
public string ContactName { get; private set; }
public BitmapImage ContactImage { get; private set; }
public Visibility CanShow { get; set; }
public List<string> PhoneNumbers { get; set; }
public List<string> ContactEmails { get; set; }
public GetContactDetails(ContactInformation c)
{
PhoneNumbers = new List<string>();
ContactEmails = new List<string>();
CanShow = Visibility.Visible;
ContactName = c.Name;
if (c.PhoneNumbers.Count > 0)
{
foreach (var item in c.PhoneNumbers)
{
PhoneNumbers.Add(item.Value);
}
}
else
{
CanShow = Visibility.Collapsed;
}
GetContactImage(c);
}
async void GetContactImage(ContactInformation Img)
{
var imgStream = await Img.GetThumbnailAsync();
ContactImage = new BitmapImage();
if (imgStream != null && imgStream.Size > 0)
{
ContactImage.SetSource(imgStream);
}
}
}