Walkthrough: Use the Source Property

This walkthrough shows how to set the Microsoft Lync 2010 Controls Source property. Use the Source property to obtain or set contact and group URIs for Lync 2010 Controls by using the Microsoft Lync 2010 SDK. For more information, see Understand the Lync 2010 SDK Source Property.

Prerequisites

For a list of prerequisites, see Walkthrough: Presence Hello World.

Using the Source Property in XAML

In the XAML Designer, set the Source property to a string.

<controls:PresenceIndicator Source="sip:mary@contoso.com"/>

Using the Source Property in C#

The following two procedures show how to use C# in the code-behind file to set the Source property of a Lync Control control to a String or to a Contact object.

Set the Source Property to a String

The following walkthrough sets Name as an extended attribute in XAML to allow the PresenceIndicator control to be referenced in the C# Code Editor, and then sets the Source property to a string value.

To create the String type walkthrough application

  1. Create a Microsoft Windows Presentation Foundation (WPF) Lync Controls application. For more information, see Walkthrough: Presence Hello World.

  2. On the Window1.xaml page, find the XAML creating the PresenceIndicator control. Ensure that an extended Name attribute is added, and the Source property is not set, as in the following example.

    <controls:PresenceIndicator x:Name="presenceIndicator"/>
    
  3. On the Window1.xaml.cs page, add the following statement in the Window1 constructor following the call to InitializeComponent. Edit the URI to provide a valid value.

    presenceIndicator.Source = "sip:mary@contoso.com";
    
  4. Press F5 to build and run the application. The PresenceIndicator control displays the correct presence status for the contact specified by using a string in C#.

Set the Source Property to a Contact Object

The following walkthrough uses the GetContactByUri method to return a specific contact, sets the contact to a Contact object, and then sets the Source property to the Contact object.

To create the Contact object walkthrough application

  1. Use steps 1 and 2 from the previous procedure to create a simple application that contains a PresenceIndicator control with the Name attribute added and the Source property not set, as shown in the previous procedure.

  2. In Window1.xaml.cs, add the following using statements.

    using Microsoft. Lync.Model;
    using Microsoft.Lync.Model.Extensibility;
    
  3. Add the following statements to the Window1constructor following the call to InitializeComponent. Edit the URI to provide a valid value.

    Client client = LyncClient.GetClient();
    Contact contact = client.ContactManager.GetContactByUri("sip:bob@contoso.com");
    presenceIndicator.Source = contact;
    
  4. Press F5 to build and run the application. The PresenceIndicator control displays the contact set by the Source property in the previous step.

See Also

Other Resources

Lync 2010 Controls