This topic demonstrates how to add Lync Controls to an existing .NET application using Microsoft Windows Presentation Foundation (WPF).

Desktop application developers using Microsoft Lync 2010 SDK are encouraged to choose WPF as their application architecture. However, applications developers who are required to use Microsoft Windows Forms API can use Lync SDK. This walkthrough demonstrates how to embed a WPF control containing Lync Controls in a Windows Forms application window.

Prerequisites

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

Creating the .NET Presence Application

To add Lync Controls to an existing .NET application, create a WPF User Control to host Lync controls, and then add the WPF control to Windows Form. The WPF control is hosted in an ElementHostcontrol. For more information, see the MSDN article Walkthrough: Creating New Windows Presentation Foundation Content on Windows Forms at Design Time. For general information about developing WPF applications, see the MSDN article Windows Presentation Foundation.

To create the walkthrough application

  1. In Microsoft Visual Studio development system, create a new Windows Forms Application project.

  2. Add project references to the following assemblies.

    • Microsoft.Lync.Model.dll

    • Microsoft.Lync.Controls.dll

    • Microsoft.Lync.Controls.Framework.dll

    • Microsoft.Lync.Utilities.dll

    • Microsoft.Office.Uc.dll

    • PresentationCore

    • PresentationFramework

    • System.XAML

    • WindowsBase

  3. As a way to identify the Form, change the Text property on the Form to Add Presenceor some other unique text.

To add a WPF control to the application

  1. Add a User Control (WPF)item to the project.

  2. On the UserControl1.xaml page, add the following xmlns attribute to the other namespace declarations near the top of the page.

      Copy imageCopy Code
    xmlns:controls="clr-namespace:Microsoft.Lync.Controls;assembly=Microsoft.Lync.Controls"
    
  3. Add the following XAML text to the Grid control.

      Copy imageCopy Code
    <controls:PresenceIndicator Source="sip:elise@contoso.com"/>
    
  4. Edit the Source property on the PresenceIndicator control to provide a valid value.

  5. Build the project.

To add the WPF control to the Windows Form

  1. Open Form1 in Design View.

  2. In the Visual Studio Toolbox, click the ExistingDotNet WPF User Controlstab. A list of user controls appears and the tab name matches the name of the application.

  3. Drag an instance of UserControl1 onto the center of the form. In the Propertieswindow, UserControl1 is now hosted in an ElementHost control.

  4. Press F5 to build and run the application. The PresenceIndicator control and the Text property appear on the Form.

See Also

Other Resources