2

在我的 WPF 应用程序中,我有一个类用作 QuickTime 的包装器。它提供了我需要的所有特定或简化的功能。为了运行,它需要创建一个 QuickTime 的 ActiveX 控件的实例并将其放置在一个有效的 Windows 窗体窗口中。我的应用程序是 WPF,构造函数的工作方式如下:

public VideoPlayerQT(WindowsFormsHost wfHost) {
    AxQTControl qtControl = new AxQTControl();
    wfHost.Child = qtControl;
}

现在在主窗口中,我像这样使用播放器:

private VideoPlayerQT videoPlayer;    

private void MainWindow_Loaded(object sender, RoutedEventArgs e) {
    this.videoPlayer = new VideoPlayerQT(myWinFormsHost);
}

这一直有效,直到我将 WindowsFormsHost 放入 TabControl 中。我想把它放在一个从一开始就没有显示的选项卡上。

这导致了一个奇怪的行为:我的VideoPlayerQT对象的构造函数试图将AxQTControl提供WindowsFormsHost的 .hwever 放在一个尚未显示的选项卡上,QuickTime 控件会抛出InvalidActiveXStateException. 我认为任何 ActiveX / COM 控件都会抛出它;我猜在WindowsFormsHost单击并显示其父选项卡之前,它处于某种“无效的 ActiveX 状态”。

我的问题是:应该在哪个事件处理程序(在哪个对象上)构建播放器?最初处于非活动状态的 TabItem 内的 WindowsFormsHost 何时准备好并加载,就像 Window_Loaded 触发时一样?

4

1 回答 1

1

The first solution I came up with is creating the player in the method handling the TabItem_GotFocus event. Works fine for now, but if there is any catch to this solution, I'd like to know :)

Also, since GotFocus is such a general event I have trouble understanding why exactly is THIS okay for the WinForms host. Is the answer simply something like "tabitem's content is rendered when it receives focus, just as window's is rendered when it's loaded"?

于 2012-11-20T08:58:28.807 回答