In my WPF application, I have a class that serves as a wrapper around QuickTime. It provides all the specific or simplified functionality I need. To function, it needs to create an instance of QuickTime's ActiveX control and place it in a valid Windows Forms window. My app being WPF, the constructor works like this:
public VideoPlayerQT(WindowsFormsHost wfHost) {
AxQTControl qtControl = new AxQTControl();
wfHost.Child = qtControl;
}
Now in the main window, I use the player like this:
private VideoPlayerQT videoPlayer;
private void MainWindow_Loaded(object sender, RoutedEventArgs e) {
this.videoPlayer = new VideoPlayerQT(myWinFormsHost);
}
This works until I put the WindowsFormsHost inside a TabControl. I want to have it on a tab that's not displayed right from the start.
This causes a strange behavior: The constructor of my VideoPlayerQT
object tries to place the AxQTControl
inside the provided WindowsFormsHost
, Hwever, being on a not-yet-displayed tab, the QuickTime control throws InvalidActiveXStateException
. I figure any ActiveX / COM control would throw that; I guess the WindowsFormsHost
is in some "invalid ActiveX state" until its parent tab is clicked and displayed.
My question is: In which event handler (on which object) should construct the player? When is the WindowsFormsHost inside initially inactive TabItem as ready and loaded, as it is when Window_Loaded fires?