c# - Suggesting contacts (emails) in 'send to' field WP8.1 -



c# - Suggesting contacts (emails) in 'send to' field WP8.1 -

so i'm trying create 'to' field suggesting email addresses matching user input string (like in screen in link) - same way in creating new email. it'll great if solution work in windows 8.1 (i'm developing universal app).

screen: http://i.imgur.com/rofanov.png

you can utilize next (it's not sophisticated, eg doesn't handle typing quickly, can prepare that). sure add together contacts capability project.

xaml

<page x:class="contactssearch.mainpage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:contactssearch" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:ignorable="d" background="{themeresource applicationpagebackgroundthemebrush}"> <grid> <stackpanel> <textbox x:name="input" textchanged="ontextchanged" isenabled="false"/> <listbox x:name="candidates" height="300"> <listbox.itemtemplate> <datatemplate> <stackpanel margin="5"> <textblock text="{binding name}" fontsize="23"/> <textblock text="{binding email}" fontsize="15" foreground="{staticresource phoneaccentbrush}"/> </stackpanel> </datatemplate> </listbox.itemtemplate> </listbox> </stackpanel> </grid> </page>

code

using system; using system.linq; using system.collections.generic; using system.diagnostics; using system.threading.tasks; using windows.applicationmodel.contacts; using windows.ui.xaml.controls; using windows.ui.xaml.navigation; namespace contactssearch { public sealed partial class mainpage : page { public mainpage() { this.initializecomponent(); this.navigationcachemode = navigationcachemode.required; } contactstore store; bool loading = false; protected override void onnavigatedto(navigationeventargs e) { if (store == null) getstoreasync().gettype(); // gettype avoids compiler warning } async task getstoreasync() { store = await contactmanager.requeststoreasync(); input.isenabled = true; debug.writeline("ready!"); } private async void ontextchanged(object sender, textchangedeventargs e) { if (store == null || loading) return; string search = (sender textbox).text; debug.writeline("looking for: '{0}'", search); loading = true; candidates.opacity = 0.8; candidates.items.clear(); ireadonlylist<contact> contacts = new list<contact>(); if (string.isnullorwhitespace(search)) contacts = await store.findcontactsasync(); else contacts = await store.findcontactsasync(search); foreach (var c in contacts) { var email = c.emails.firstordefault(); if (email == null) continue; candidates.items.add(new contactinfo { name = c.displayname, email = email.address }); } debug.writeline("found {0} contacts", candidates.items.count); loading = false; candidates.opacity = 1; } } public class contactinfo { public string name { get; set; } public string email { get; set; } } }

note seems crash randomly within xaml might need ignore bogus exceptions in global unhandledexception handler in app.xaml.cs

c# xaml windows-phone-8.1 contacts

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -