Embedding YouTube in WPF WebBrowser control

By | 2010.06.27

Embedding YouTube into your C# WPF application can be done by wrapping embedded YouTube in a WebBrowser object (Internet Explorer). There are a couple of things you need to do to make it work.

Tested on Windows 7 Ultimate 64-bit in .Net 3.5 (VS 2010). Sample code can be found at the bottom.

  1. Add Mark of the Web to the HTML code: http://msdn.microsoft.com/en-us/library/ms537628(VS.85).aspx
  2. Make sure you \r\n format your HTML-code. I read somewhere that some people had difficulties because the HTML was Mac-formatted.
  3. Make sure your app is set to execute as x86 (project properties) since it will use Flash which is not released as 64-bit yet. I spent quite some time debugging before it finally occurred to me that it was running as x64.

The Code I’m using:

Inside XAML:

In codebehind:

Result when embedded into RTF control:

Leave a Reply