Skip to content

Instantly share code, notes, and snippets.

@enisn
Created March 5, 2018 07:25
Show Gist options
  • Save enisn/25fd0a63a849854fb6103aa681be9963 to your computer and use it in GitHub Desktop.
Save enisn/25fd0a63a849854fb6103aa681be9963 to your computer and use it in GitHub Desktop.
Xamarin.Forms.Contacts Sample
<uses-permission android:name="android.permission.READ_CONTACTS" />
<key>NSContactsUsageDescription</key>
<string>We need contact permission to do ...</string>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Sample.ContactService
{
public partial class MainPage : ContentPage
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
public MainPage()
{
InitializeComponent();
GetContacs();
}
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
async Task GetContacs()
{
var contacts = await Plugin.ContactService.CrossContactService.Current.GetContactListAsync();
lstContacts.BindingContext = contacts;
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Sample.ContactService"
x:Class="Sample.ContactService.MainPage">
<StackLayout>
<ListView
x:Name="lstContacts"
ItemsSource="{Binding .}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="{Binding Name}"/>
<Label Text="{Binding Email}"/>
<Label Text="{Binding Number}"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment