Panel Overlay over WindowsFormsHost

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

I want to add a toolbar to a swf movie.

The problem with the code snippet that I have below is that when a new child is added to the host control (or the movie is loading, I have not figured out what else), the toolbar becomes invisible. It seems that the z-index swf is for some reason set to the top.

Here's 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>

WITH#:

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 understanding of this problem would be greatly appreciated.


Update: . Since no suitable answer has been posted, I posted my own solution below. I understand that this is more of a hack than a solution, so I am open to other suggestions.

+3
2

, , ElementHost Windows Forms. Windows Form WPF, Windows Z-Issue.

ElementHost , UserControl Windows. , Windows Forms, :

, ActiveX, ElementHost Control, .

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);
}

, . , UserControls ( ).

, , , : UserControls XAML, Z-.

0

WindowsFormsHost Z-index.

, , , . / .

. , , /, , ( ).

XAML:

<Window [stuff]
   LocationChanged="Window_LocationChanged"
   SizeChanged="Window_SizeChanged" >
   <Grid Name="Player">
   [same code as before]
       <Popup Name="toolbar_popup" IsOpen="True" PlacementTarget="{Binding ElementName=host}">
           [toolbar grid goes here]
       </Popup>
   </Grid>
</Window>

#:

private void resetPopup()
{
   // Update position
   // /questions/137957/how-can-i-move-a-wpf-popup-when-its-anchor-element-moves/820855#820855
   var offset = toolbar_popup.HorizontalOffset;
   toolbar_popup.HorizontalOffset = offset + 1;
   toolbar_popup.HorizontalOffset = offset;

   // Resizing
   toolbar_popup.Width = Player.ActualWidth;
   toolbar_popup.PlacementRectangle = new Rect(0, host.ActualHeight, 0, 0);
   toolbar_popup.Placement = System.Windows.Controls.Primitives.PlacementMode.Top;
}
private void Window_LocationChanged(object sender, EventArgs e)
{ resetPopup(); }

private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{ resetPopup(); }
+1

All Articles