Question

Problems hosting a WinForms control in a ToolWindow

Posted 2 years ago by Avatar Geir Schjorlien

Hi,

In my WPF application, I have a WinForms user-control containing Windows Media Player. In addition I have a WPF user-control containing the WinForms media-player control like this:

<UserControl 
   x:Class="MyControls.MediaPlayer"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
   xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
   xmlns:windowsformscontrols="clr-namespace:MyWindowsForms.Controls;assembly=MyWindowsForms.Controls"
   mc:Ignorable="d" 
   Width="Auto" Height="Auto">

   <Grid Margin="2,2,2,2">
      <WindowsFormsHost>
         <windowsformscontrols:WMPControl x:Name="WindowsMediaPlayer"/>
      </WindowsFormsHost>
   </Grid>
</UserControl>

I'm hosting this media-player control in a ToolWindow like this:

MediaPlayerWindow = new ToolWindow(MyDockSite, "MediaPlayerWindow", "Media Player", null, new MyControls.MediaPlayer());
MediaPlayerWindow.CanRaft = true;
MediaPlayerWindow.CanDockBottom = false;
MediaPlayerWindow.CanDockLeft = false;
MediaPlayerWindow.CanDockRight = false;
MediaPlayerWindow.CanDockTop = false;
MediaPlayerWindow.CanBecomeDocument = false;

My problem is that when the "MyControls.MediaPlayer" is hosted in a ToolWindow, it becomes "invisible". The window just shows a white background. I know that the control is there because I get the Windows Media Player tooltips when moving the mouse over the ToolWindow. The "MyControls.MediaPlayer" control displays normally when hosted in other "normal" windows. I also created a simpler WinForms user-control containing just a button, but got the same behavior.

So my question: Do you know of any problems hosting a "WindowsFormsHost" in a ToolWindow?

Kind regards,

Geir


Comments (1)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Geir,
The problem you are having is most likely because of the settings required for compatibility with interop controls. You can read more extensively about this in the documentation under Docking & MDI > Interoperability > WinForms Compatibility. Your issue is probably caused by the AllowsTransparency property needing to be false in order for interop controls to function correctly. If you follow the directions in the documentation to set up compatibility the property will automatically be set to false though.


Actipro Software Support
Information The latest build of this product (2014.1 build 0601) was released 29 days ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.