There are three kinds of state change events that are raised on
an individual contact. These events can only be raised when the
contact has been added to a
Contact Events
The following sections provide examples that handle the three kinds of contact events.
Contact Information Changed
The following example handles the event raised when contact
information is updated. It is important to note that this example
queries the
dataparameter property,
C# | Copy Code |
---|---|
/// <summary> /// Handles event raised when contact contact information item collection has been updated. /// </summary> /// <param name="source">object. Contact whose information has been updated.</param> /// <param name="data">ContactInformationChangedEventArgs. The contact information that changed.</param> /// <remarks>This callback is used to update the public contactModel card string class property ContactCardInformation. /// The event data parameter exposes a member property, ChangedPresenceItems. This property is a list of ContactInformationType. The types in /// the list are the presence item types whose change resulted in this state change event. /// </remarks> void _Contact_OnInformationChanged(Object source, ContactInformationChangedEventArgs data) { try { string newCard = string.Empty; StringBuilder sb = new StringBuilder(); if (data.ChangedContactInformation.Contains(ContactInformationType.Availability)) { object availability = ((Contact)source).GetContactInformation(ContactInformationType.Availability); object activityString = ((Contact)source).GetContactInformation(ContactInformationType.Activity); if (availability != null) { sb.Append(availability.ToString() + " " + activityString.ToString()); newCard = "Updated availability for " + ((Contact)source).GetContactInformation(ContactInformationType.DisplayName).ToString() + System.Environment.NewLine + sb.ToString(); } } } catch (System.IO.InvalidDataException x) { WinForm.MessageBox.Show("Invalid Data Exception, Contact.ContactInformationChanged " + x.Message); } } |
Contact Setting Changed
The following example handles a contact property changed event by getting the type of property that changed and the new value. The result is displayed to a user in a MessageBox .
C# | Copy Code |
---|---|
/// <summary> /// Event handler for ContactModel event raised when a setting on a contactModel has changed. /// </summary> /// <param name="source">Contact. The ContactModel instance whose inner Contact setting has changed.</param> /// <param name="data">ContactSettingChangedEventArgs. Event data.</param> private void ContactModel_ContactSettingChanged(object source, ContactSettingChangedEventArgs data) { string ChangedProperty = string.Empty; switch (data.Setting) { case ContactSetting.AccessLevel: ChangedProperty = ((Contact)source).GetContactInformation(ContactInformationType.DisplayName).ToString() + " access level changed " + data.Value.ToString(); break; case ContactSetting.DefaultContactEndpoint: ChangedProperty = ((Contact)source).GetContactInformation(ContactInformationType.DisplayName).ToString() + " default endpoint changed " + data.Value.ToString(); break; case ContactSetting.ExchangeServiceEntryId: ChangedProperty = ((Contact)source).GetContactInformation(ContactInformationType.DisplayName).ToString() + " Exchange service Entry Id " + data.Value.ToString(); break; case ContactSetting.Source: ChangedProperty = ((Contact)source).GetContactInformation(ContactInformationType.DisplayName).ToString() + " Sources changed " + data.Value.ToString(); break; case ContactSetting.Tagged: ChangedProperty = ((Contact)source).GetContactInformation(ContactInformationType.DisplayName).ToString() + " Tagging changed " + data.Value.ToString(); break; } MessageBox.Show("Contact Setting Changed: " + ChangedProperty); } |
Contact Uri Changed
The following example handles the event raised when a contact's Uri has changed. The example uses a MessageBox to alert a user of the change.
C# | Copy Code |
---|---|
/// <summary> /// Alerts user when a Contact Uri has changed /// </summary> /// <param name="source">object. Contact whose Uri has changed</param> /// <param name="data">UriChangedEventArgs Event data</param> void _Contact_OnUriChanged(Object source, UriChangedEventArgs data) { System.Windows.Forms.MessageBox.Show(((Contact)source).GetContactInformation(ContactInformationType.DisplayName).ToString() + " uri changed to " + data.NewUri); } |