In VSTA 2.0, you have the ability to use WPF. In this post, we will show a simple example to add video to a VSTA add-in using WPF. We will start with ShapeAppCSharpBasic Example. Launch VSTA using "vsta.exe /hostid ShapeAppCSharp", Create a new C# project choosing ShapeAppCSharp-AppLevel template, accept the default name:
Go to Project Menu, choose "Add Windows Form ..." to add a WinForm. Choose "Add User Control " to add a WPF user control:
Open Toolbox, in Controls group, drag MediaElement control onto the WPF user control. Resize and position the MediaElement properly. If you do not have a sample video file, you can download one of the Visual Studio "How Do I?" videos. Rename the video to sample.wmf and put it under "c:\temp". MediaElement requires at least Window Media Player 11. If needed, download and install Window Media Player 11.
Now in XAML view, add source attribute to the MediaElement like:
<MediaElement Margin="12,22,23,27" Name="mediaElement1"
Note for simplicity, the video file path is hardcoded and we simply play the video when the WPF user control is loaded and will not go into the rich functionality of MediaElement.
Build the project. If you get compilation error like "The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)", remove the corresponding "using System.Linq;" accordingly.
Go to the WinForm control we added, open Toolbox, in WPF interoperability group, drag ElementHost onto the WinForm, and in ElementHost Tasks pop-up window, choose the WPF user control we created: UserControl1, as the Hosted Content:
In AppAddIn.cs, add the following code to AppAddIn_Startup:
private void AppAddIn_Startup(object sender, EventArgs e)
Form1 f = new Form1();
Build again and run the project. Voila! You now have a video introduction for ShapeApp!
Enzhou WangSoftware Development Engineer