ContactPicker クラスを使用して、Windows 8 People アプリをアプリケーションに統合しています。ボタンをクリックすると、People アプリが読み込まれます。ユーザーが何人かの友達を選び、その名前、画像、メール アドレスを 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);
}
}
}