TUTORIAL: Host our multimedia ActiveX Controls in a WPF Application:
1- Start Visual Studio 2008.
2- Choose File => New Project, select C# and choose 'WPF Application' from the project templates. Name the project 'LEADPlayer_WPF'.
3- From the 'Solution Explorer' Menu, right-click on the 'LEADPlayer_WPF' solution and Add a new Project. Select the project type to be a 'Windows Forms Control Library' and name the project 'UserPlayerControl'.
4- Open the Toolbox, and add an ltmmPlayCtrl control to the UserControl form.
If the ltmmPlayCtrl does not exist in the Toolbox, do the following:
- Right-click in the Toolbox.
- Click Choose Items.
- Click the COM Components tab.
- Select the 'ltmmPlayCtrl' control.
- Click OK to accept the selection.
5- In Solution Explorer, right-click the UserControl1 file, and then click Rename. Rename the control to PlayControl.cs. If you are prompted to rename all references, click Yes.
6- Set the Dock property of the ltmmPlayCtrl control to Fill.
7- Right-click 'PlayControl.cs' in solution explorer, choose 'View Code' and add the following two methods after the PlayControl() function:
public void Stop ()
{
this.axltmmPlayCtrl1.Stop();
}
public void Play(string File)
{
this.axltmmPlayCtrl1.sourcefile = File;
this.axltmmPlayCtrl1.Run();
}
8- Right-click 'Window1.xaml' and choose 'View Designer'.
9- Add a text box, two buttons and modify the buttons properties as follows:
Button1:
Control Name: btnPlay
Control Content: Play
Button2:
Control Name: btnStop
Control Content: Stop
10- Go to the Window1.xaml file in the XML editor and add a handler for the Window Loaded, btnPlay Click and btnStop events and give the grid tag a name. The code will be as follows:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="402" Width="367" Loaded="Window_Loaded">
Play
Stop
11- Rebuild 'UserPlayerControl' and add the following references to 'LEADPlayer_WPF':
- UserPlayerControl.dll
- System.Windows.Forms.dll
- WindowsFormsIntegration.dll
12- In 'Window1.xaml.cs' add the following to the beginning of the file:
using System.Windows.Forms;
using System.Windows.Forms.Integration;
And define the following global variable:
UserPlayerControl.PlayControl uc1;
13- In the Window_Loaded event, the following code
WindowsFormsHost host = new WindowsFormsHost();
uc1 = new UserPlayerControl.PlayControl();
host.Child = uc1;
DockPanel.SetDock(host, Dock.Top);
this.grid1.Children.Add(host);
textBox1.Text = "c:\\sample.avi";
14- In the btnPlay_Click event, the following code
uc1.Play(textBox1.Text);
15- In the bntStop_Click event, add the following code:
uc1.Stop();
16- Compile and run.
The following post also shows how to add ltmmPlayCtrl to a C# WPF application:
http://support.leadtools.com/SupportPortal/CS/forums/25580/ShowPost.aspx