Getting started with Lync controls is actually quite easy. In this post, we will explore the basic steps required to create a sample application using Lync controls, and then we will run a simple “Hello, Lync” application which shows a presence indicator with photo.

Creating your first Lync Controls project

We’ll use the WPF application libraries in this sample.

1. To begin, you must first install and sign in to Microsoft Lync.  All Lync controls require a running instance of Microsoft Lync to function properly.

2. Next, be sure you have installed the Lync Client Platform SDK.

3. Open Visual Studio, and create a new project using the template Lync WPF Application

4. Open the file Window1.xaml

The template already includes some very basic XAML which instantiates a PresenceIndicator control and a TextBlock:

<!--

    Show the presence indicator. Hover over the icon to see the contact card.

    Set Source to a valid SIP URI in your organization.

-->

<controls:PresenceIndicator

    x:Name="Presence"

    Source="sip:john@contoso.com"

    PhotoDisplayMode="Large"

/>

<!-- Use the DisplayName property from PresenceIndicator to show the user's name -->

<TextBlock

    Text="{Binding DisplayName, ElementName=Presence}"

    Margin="4,0,0,0"

    VerticalAlignment="Center"

/>

If you run the application at this point, you are very likely to see the result “Unknown Contact” in the text block, along with the default silhouette image and grey presence bar.  This is because we have not yet selected a valid contact.

Connecting your control to a source of data

All Lync Controls which operate on a single contact support a property called Source which is used to tell the control which contact should be displayed. The Source property accepts any string, and the control will search for a contact matching that string. While this behavior is very robust, it tends to yield inconsistent results. A search for a string such as “Joe” or “Mary” in an organization of any non-trivial size is likely to return more than one result, and the one which gets returned first is the one which your control will display.

You can make the control behave in a more deterministic fashion by giving it more specific source criteria. One option is to use the Lync API to find a Contact object which meets your needs, and pass that object to the Source of your control in the code-behind; but using that API adds some complexity to your code which isn’t necessary for most applications. A simpler option, which works very well, is to specify the SIP URI value for the contact you wish to use. In fact, if you provide a SIP URI and be sure to prefix it with the string sip:, the Lync Control will load your contact much more quickly, because it does not perform a search. Instead, it simply asks the server for the specific contact you are requesting, based on an exact match of the specified SIP URI.

You can easily view a user’s SIP URI in Lync by simply unchecking the option “Show Friendly Name” in the contact list options menu which appears on the right hand side of the contact list toolbar. Once you know the SIP URI of the contact you wish to display, you can wire up your application:

6. Edit the XAML for your new window, and edit the Source property on your presence indicator. For this example, use your own SIP URI.  The XAML will look something like this:

<controls:PresenceIndicator

    x:Name="Presence"

    Source="sip:schuddle@microsoft.com"

    PhotoDisplayMode="Large"

/>

Despite having assigned a valid SIP URI, the TextBlock still shows the value “Unknown Contact” in the design-time preview.  Not to worry, we can leave this value alone, and let the magic of binding take care of that problem.  As you can see, the Text property of our TextBlock is bound to the DisplayName of the presence control.  This setting will automatically update at runtime when the PresenceIndicator control resolves to our selected contact.

Try running your application now.  You should see something like this:

And, you’re done! Congratulations, you have just created your first application using the new Lync Client Platform SDK.

As you have seen, it is really very simple to add Unified Communications functionality into your applications. But there is much more you can do with these controls once you are familiar with the basic interface they support. In our next post, we will explore the contact search controls, and how they can be used to integrate Lync’s powerful search feature into your application.