工具栏覆盖WindowsFormsHost [英] Toolbar Overlay over WindowsFormsHost

查看:417
本文介绍了工具栏覆盖WindowsFormsHost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在swf电影中添加一个工具栏。

我有一个SWF对象嵌入到WPF窗口中的WindowsFormsHost控件中。

下面的代码片段的问题是,当新的孩子被添加到主控制器(或电影被加载,我还没有想出) ,工具栏实际上是不可见的。看起来swf的z-index是由于某种原因设置在最上面的。



以下是它的样子:



XAML:

 < Grid Name =Player> 
< WindowsFormsHost Name =hostPanel.ZIndex =0/>
< Grid Name =toolbarPanel.ZIndex =1Height =50
VerticalAlignment =Bottom>
[play,pause,seek columns go here]
< / Grid>
< / Grid>

C#:

  private void Window_Loaded(object sender,RoutedEventArgs e)
{
flash = new AxShockwaveFlashObjects.AxShockwaveFlash();
host.Child = flash;
flash.LoadMovie(0,[movie]); //电影播放,但没有工具栏:(

非常感谢。






更新:我自己的解决方案下面我意识到这是一个解决方案,所以我打开其他建议更多的破解。

解决方案

我发现的另一个解决方案是使用Windows窗体的ElementHost控件,因为我在WPF窗口中使用Windows窗体,为什么不使用整个Windows窗体并保存自己的Z-Issue头疼。 b
$ b

ElementHost控件是非常有用的,因为我仍然可以使用我的工具栏UserControl,并将其嵌入到Windows窗体中,我发现添加一个子窗体可以用Windows窗体进行挑剔,所以这里有一个描述解决方案的片段:首先,使用设计器,在ActiveX对象中抛出一个ElementHost控件。

b Form1.Designer.cs:

 私人的AxShockwaveFlashObjects.AxShockwaveFlash flash; 
private System.Windows.Forms.Integration.ElementHost elementHost1;

Form1.cs

  public Form1(string source)
{
InitializeComponent();
toolbar = new UserControl1();
this.elementHost1.Child = this.toolbar;
this.flash.LoadMovie(0,source);



$ b $ p
$ b

请注意,在设计器中没有设置孩子。我发现对于更复杂的UserControl,设计者会抱怨(尽管在运行时没有任何反应)。

这个解决方案当然还不完全理想,但它提供了最好的两个世界:我仍然可以编写我的用户控件在XAML中,但现在我不必担心Z索引问题。


I have a SWF object embedded in a WindowsFormsHost Control inside a WPF window.

I'd like to add a toolbar over the swf movie.

The problem with the snippet of code I have below, is that when the new child is added to the host control (or the movie is loaded, I haven't figured out which yet), the toolbar is effectively invisible. It seems like the z-index of the swf is for some reason set to the top.

Here is what it looks like:

XAML:

<Grid Name="Player">
   <WindowsFormsHost Name="host" Panel.ZIndex="0" />
   <Grid Name="toolbar" Panel.ZIndex="1" Height="50"
      VerticalAlignment="Bottom">
           [play, pause, seek columns go here]
   </Grid>
</Grid>

C#:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
   flash = new AxShockwaveFlashObjects.AxShockwaveFlash();
   host.Child = flash;
   flash.LoadMovie(0, [movie]); // Movie plays, but no toolbar :(
}

Any insight on this issue would be much appreciated.


Update: Since no suitable answer was posted, I've placed my own solution below. I realize this is more of a hack than a solution so I'm open to other suggestions.

解决方案

Another solution I've discovered is to use Windows Forms' ElementHost control. Since I'm using a Windows Form inside a WPF window anyway, why not just use an entire Windows Form and save myself Z-Issue headaches.

The ElementHost control is really useful, because I can still use my toolbar UserControl, and embed it inside the Windows Form. I've discovered that adding a child can be finicky with Windows Forms, so here's a snippet describing the solution:

First, toss in the ActiveX object, then an ElementHost Control, using the designer.

Form1.Designer.cs:

private AxShockwaveFlashObjects.AxShockwaveFlash flash;
private System.Windows.Forms.Integration.ElementHost elementHost1;

Form1.cs

public Form1(string source)
{
     InitializeComponent();
     toolbar = new UserControl1();
     this.elementHost1.Child = this.toolbar;
     this.flash.LoadMovie(0, source);
}

Note that the child was not set in the designer. I found that for more complex UserControls the designer will complain (though nothing happens at runtime).

This solution is, of course, still not entirely ideal, but it provides the best of both worlds: I can still code my UserControls in XAML, but now I don't have to worry about Z-indexing issues.

这篇关于工具栏覆盖WindowsFormsHost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆