Sunday, August 24, 2008

Communicator Presence Controls in WPF

Last night I was preparing some ideas for a demo application I need later this week. The demo app had to look good and should be fun and interesting in the making. So I decided to code the UI in Windows Presentation Foundation (WPF). Code in XAML for WPF is simple and one will soon get the hang of it. So I went using some ListViews filled with data via LINQ to SQL and a data class. When I came to implementing Office Communicator 2007 functionality I realized that the “Microsoft Office Communicator 2007 Presence Controls” did only exists as Windows Forms User Controls and not as WPF user controls. Facing the choice of coding my own controls or try to make use of the existing Win Form controls I browsed around and found a XAML tag which enables you to host a windows forms control on a WPF page and the great part about it is really easy to use:

  1. Download the above mentioned controls from Microsoft and install them.
  2. Include the managed controls into you WPF project solution.
  3. Add the WindowsFromHost tag to the WPF XAML page.
  4. Add the necessary XML name spaces. Look for xmlns:q1 and xmlns:q2 in the example below
  5. Add the xml tag for persona list control - "q1:Personalist"
<Window x:Class="WPFHostingPresenceControls.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:q1="clr-namespace:Microsoft.Samples.Office.UnifiedCommunications.PresenceControls;assembly=PresenceControls"
xmlns:q2="clr-namespace:Microsoft.Samples.Office.UnifiedCommunications.PresenceBase;assembly=PresenceControls"
Title="Window1" Height="300" Width="300">
<Grid>
<WindowsFormsHost Name="windowsFormsHost1">
<q1:PersonaList x:Name="plMyPersonaList"/>
</WindowsFormsHost>
</Grid>
</Window>




Here after you can populate the list via code:




public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
plMyPersonaList.AddRange("pli@inceptio.dk", "someone@inceptio.dk");
}
}




and when you compile you should have something like this.



WPFHostingPrecenseControls

1 comment:

Anonymous said...

According to the Readme file, Communicator must be installed on the workstation running the client app for the controls to appear. Major bummer... would be good if only MSN Messenger were necessary at a minimum.