UI:
<Page
x:Class="App9.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App9"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<DataTemplate x:Key="contactTemplate">
<Grid Width="600" Height="300">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="75"></RowDefinition>
<RowDefinition Height="75"></RowDefinition>
<RowDefinition Height="75"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding ContactName}"/>
</Grid>
</DataTemplate>
</Page.Resources>
<Grid Background="ForestGreen">
<ListView x:Name="lstContact" Margin="100,80,90,90" ItemTemplate="{StaticResource contactTemlate}"/>
<Button x:Name="btnContact" Content="View Contact" HorizontalAlignment="Left" Margin="100,10,0,0" VerticalAlignment="Top" Click="btnContact_Click"/>
</Grid>
</Page>
Code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel.Contacts;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace App9
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
List<ContactDetails> s;
public List<ContactDetails> Details { get { return s; } set { s = value; } }
private async void btnContact_Click(object sender, RoutedEventArgs e)
{
Details = new List<ContactDetails>();
var p = new ContactPicker();
p.CommitButtonText = "Pick Contact";
var selectedContact = await p.PickSingleContactAsync();
Details.Add(new ContactDetails(selectedContact));
lstContact.ItemsSource = Details;
}
public class ContactDetails
{
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 ContactDetails(ContactInformation c)
{
PhoneNumbers = new List<string>();
ContactEmails = new List<string>();
CanShow = Visibility.Visible;
ContactName = c.Name;
foreach (var item in c.Emails)
ContactEmails.Add(item.Value);
}
}
}
Reference : http://msdn.microsoft.com/en-us/library/windows/apps/xx130650.aspx
0 nhận xét:
Đăng nhận xét