Selector: Contact Selection window, customizing the Contact Selection window
Introduced
Re-imagine the Windows 8 Store Apps Selector
Contactpicker-Contact Selector
Contactpickerui-Custom Contact Selector
Example
Demonstrates how to select one or more contacts through contactpicker and how to develop custom contact selectors
1. Develop a custom contact selector
Picker/mycontactpicker.xaml
<page
x:class= "XamlDemo.Picker.MyContactPicker"
xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml /presentation "
xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "
xmlns:local=" using: Xamldemo.picker "
xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "
xmlns:mc=" http:// schemas.openxmlformats.org/markup-compatibility/2006 "
mc:ignorable=" D ">
<grid background=" Transparent ">
<stackpanel margin=" 0 0 0 ">
<textblock name=" lblmsg "fontsize=" 14.667 "/>
<button name= "Btnaddcontract" content= "Add a Contact" click= "Btnaddcontract_click" margin= "0 0 0"
/> </StackPanel>
</Grid>
</Page>
Picker/mycontactpicker.xaml.cs
* * Demonstrates how to develop a custom contact Picker * 1, add a "contact selector" declaration in Package.appxmanifest, and make a related configuration * 2, override void Onactiva in App.xaml.cs Ted (Iactivatedeventargs args) to get information about the Contact Picker * Contactpickeractivatedeventargs-event arguments when activating an application through the contact selector * Contac
Tpickerui-Get Contactpickerui objects * previousexecutionstate, Kind, SplashScreen-the various event parameters that activate the app are basically all of these attributes, and it's not much to say * Contactpickerui-Customize the Help class for the contact Picker * SelectionMode-Get the SelectionMode property set by the Contactpicker (caller) * Desiredfields -Get the Desiredfields property * ADDCONTACT (string ID, contact contacts) set by Contactpicker (caller)-Select a person * ID-Contact Sign Know * Contact-a Touch Object * removecontact ()-Deletes the specified identity's contacts * CONTAINSCONTACT ()-Specifies whether the identified contact has been selected * Contactremoved-Event triggered by removing a selected contact-the contact object returned to the caller * name-name * Thumbnail-Thumbnail * fiel DS-Contact field data, each data is an object that implements the Icontactfield interface * * Contactfield-implements the Icontactfield interface, which describes one field data * Type of the contact person -Field type (ContactfieldtypeEnum) * Email, PhoneNumber, Location, Instantmessage, Custom * Category-field category (Contactfieldcategory enumeration) *
None, Home, Work, Mobile, other * value-field values * * using System;
Using Windows.ApplicationModel.Activation;
Using Windows.ApplicationModel.Contacts.Provider;
Using Windows.UI.Xaml;
Using Windows.UI.Xaml.Controls;
Using Windows.UI.Xaml.Navigation;
Using Windows.ApplicationModel.Contacts;
Using Windows.Storage.Streams;
Using Windows.UI.Core; Namespace Xamldemo.picker {public sealed partial class Mycontactpicker:page {Private Contactpickerui _
Contactpickerui; Public Mycontactpicker () {this.
InitializeComponent ();
} protected override void Onnavigatedto (NavigationEventArgs e) {//Get Contactpickerui Object
var contactpickeractivated = e.parameter as Contactpickeractivatedeventargs; _contactpickerui = Contactpickeractivated.contactpickerui;
_contactpickerui.contactremoved + = _contactpickerui_contactremoved; } protected override void Onnavigatedfrom (NavigationEventArgs e) {_contactpickerui.conta
ctremoved-= _contactpickerui_contactremoved; ///Remove the Async void _contactpickerui_contactremoved from the selection buffer (Contactpickerui sender, Contactremovedevent
Args Args) {//NOTE: You cannot directly tell if Contactpickerui is a single or multiple mode, you need to decide that when you add a contact, add a contact, if the system will automatically remove the previous contact, it is a single mode Await this. Dispatcher.runasync (Coredispatcherpriority.normal, () => {lblmsg.text = "removed contact: "+ args."
Id;
Lblmsg.text + = Environment.NewLine;
}); } private void Btnaddcontract_click (object sender, RoutedEventArgs e) {Random Random = n
EW Random ();
Construct a Contact object contact = new Contact (); Contact. Name = "WeBABCD "+ random. Next (1000, 10000).
ToString (); Contact. Fields.Add (New Contactfield (random). Next (1000, 10000).
ToString (), Contactfieldtype.email, contactfieldcategory.home)); Contact. Fields.Add (New Contactfield (random). Next (1000, 10000).
ToString (), Contactfieldtype.email, contactfieldcategory.work)); Contact. Fields.Add (New Contactfield (random). Next (1000, 10000).
ToString (), Contactfieldtype.phonenumber, contactfieldcategory.home)); Contact. Fields.Add (New Contactfield (random). Next (1000, 10000).
ToString (), Contactfieldtype.phonenumber, contactfieldcategory.work)); Contact.
Thumbnail = Randomaccessstreamreference.createfromuri (New Uri ("Ms-appx:///assets/logo.png", Urikind.absolute)); String id = Guid.NewGuid ().
ToString (); Add a new contact switch to the selection buffer (_contactpickerui.addcontact (ID, contacts)) {case Addconta Ctresult.added://has been successfully added Lblmsg.text + = "Added Contact:" + ID;
Lblmsg.text + = Environment.NewLine;
Break
Case addcontactresult.alreadyadded://Select buffer already has this contact person lblmsg.text + = "Already added contacts:" + ID;
Lblmsg.text + = Environment.NewLine;
Break
Case addcontactresult.unavailable://Invalid contact person Lblmsg.text + = "Unavailable contacts:" + ID;
Lblmsg.text + = Environment.NewLine;
Break }
}
}
}
2, determine whether the program is activated by the contact selector, in App.xaml.cs override void Onactivated (Iactivatedeventargs args)
App.xaml.cs
protected override void Onactivated
(Iactivatedeventargs args)
{
//if (args) activates the application through the contact selector
. Kind = = Activationkind.contactpicker)
{
Contactpickeractivatedeventargs Contactpickerargs = args as Contactpickeractivatedeventargs;
Frame rootframe = new Frame ();
Rootframe.navigate (typeof (MainPage), Contactpickerargs);
Window.Current.Content = Rootframe;
Window.Current.Activate ();
}