In this post you will find out what you need to do if you want to add a Facebook Like button to your Silverlight application.
The strait forward approach is to add a button to your application and make it look the same as the one on Facebook. Then you need to Facebook authenticate the person that clicked the like button and add your Facebook page to the list of pages that he likes. This is very difficult to implement and requires knowledge of the Facebook API. You can also try to use the Codeplex Facebook SDK but that requires you to have a Facebook application, if you have a Facebook personal page or a website the SDK will not help.
The simple way to do this is to integrate the Html Facebook like button into your Silverlight application. In order to do this you need an HtmlHost control that will display the Html like button. Since the standard Microsoft WebBrowser control only works when running in out-of-browser mode I have used the divelements free HtmlHost control. In order to use this control you need to set windowless parameter of your Silverlight plugin to true.
Here is a step by step example:
1) Create a new project named FacebookLikeApplication in Visual Studio 2010 using the SilverlightApplication template; when creating the project check the “Host the Silverlight application in a new Web site” option
2) Download the divelements Silverlight Tools from here; extract, unblock and add a reference of Divelements.SilverlightTools.dll to your FacebookLikeApplication project
3) Open the FacebookLikeApplicationTestPage.aspx and FacebookLikeApplicationTestPage.html, identify the <object .. /> element and add windowless parameter
4) Open the MainPage.xaml and add the HtmlHost control
5) Open the Facebook Like button website from here, fill in the fields and retrieve the Facebook like IFrame
6) Open the MainPage.xaml.cs and set the Facebook like IFrame to htmlHost.SourceHtml property; after you set the value replace the double quotes from the IFrame text with a single quote
That’s it! Now you can build and run the application.
Don’t forget to drop me a comment to let me know what you think.
You can download the sample application from here.