Enables your app to create a new contact. Available only if your app uses the Contact contract.
Syntax
var contact = new Windows.ApplicationModel.Contacts.Contact();
Attributes
- ActivatableAttribute(NTDDI_WIN8)
- MarshalingBehaviorAttribute(Standard)
- VersionAttribute(NTDDI_WIN8)
Members
The Contact class has these types of members:
Constructors
The Contact class has these constructors.
| Constructor | Description |
|---|---|
| Contact | Creates a new instance of the Contact class. |
Methods
The Contact class inherits methods from the Object class (C#/VB/C++).
Properties
The Contact class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read-only | Sets the fields that contain information about a contact. | |
| Read/write | Sets and gets the name of the contact. | |
|
Thumbnail | Read/write | Gets or sets a thumbnail image that represents this contact. |
Remarks
No matter how you store contact information in your app, you must be able to put that information into a Contact object. This way, other apps that allow users to select contacts can use your app and process the contact information it provides.
Note : This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX) and Using Windows Runtime objects in a multithreaded environment (.NET).
Examples
This code shows how your app can take an app-specific contact object and use it to create a Contact object. First, here's an example of an object that contains contact information.
var appContact = { name: "David Jaffe", homeEmail: "david@contoso.com", workEmail: "david@cpandl.com", homePhone: "", workPhone: "", homePhone: "248-555-0150", address: { full: "3456 Broadway Ln, Los Angeles, CA", street: "", city: "", state: "", zipCode: "" }, id: "761cb6fb-0270-451e-8725-bb575eeb24d5" };
This function creates the contact:
function createContactForBasket(contact) { var basketContact = new Windows.ApplicationModel.Contacts.Contact(); var fields = basketContact.fields; basketContact.name = contact.name; appendEmail(fields, contact.homeEmail, Windows.ApplicationModel.Contacts.ContactFieldCategory.home); appendEmail(fields, contact.workEmail, Windows.ApplicationModel.Contacts.ContactFieldCategory.work); appendPhoneNumber(fields, contact.homePhone, Windows.ApplicationModel.Contacts.ContactFieldCategory.home); appendPhoneNumber(fields, contact.workPhone, Windows.ApplicationModel.Contacts.ContactFieldCategory.work); appendPhoneNumber(fields, contact.mobilePhone, Windows.ApplicationModel.Contacts.ContactFieldCategory.mobile); appendAddress(fields, contact.address, Windows.ApplicationModel.Contacts.ContactFieldCategory.none); return basketContact; }
Contacts support a number of fields. To make adding these fields easier, the preceding function calls a few helper functions:
function appendField(fields, value, type, category) { if (value) { fields.append(new Windows.ApplicationModel.Contacts.ContactField(value, type, category)); } }
function appendEmail(fields, email, category) { // Adds a new email to the contact fields vector appendField(fields, email, Windows.ApplicationModel.Contacts.ContactFieldType.email, category); }
function appendPhoneNumber(fields, phone, category) { // Adds a new phone number to the contact fields vector appendField(fields, phone, Windows.ApplicationModel.Contacts.ContactFieldType.phoneNumber, category); }
function appendAddress(fields, address, category) { // Adds a new address to the contact fields vector if (address) { fields.append(new Windows.ApplicationModel.Contacts.ContactLocationField( address.full, category, address.street, address.city, address.state, "", address.zipCode)); } }
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps only] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps only] |
|
Namespace |
|
|
Metadata |
|
Build date: 12/4/2012