views:

10

answers:

1

Hi,

Just wondering if hosting a WindowsFormsHost control in a WPF user control in the following way is a good practice or not:

 <DockPanel LastChildFill="True">        
        <WindowsFormsHost Name="myHost">
        </WindowsFormsHost>        
 </DockPanel>

private class MyWPFUserControl:UserControl
{
   private SomeControl ForeignControl; // SomeControl is a Windows Forms Control.

   public MyWPFUserControl()
   {
     ForeignControl =  new SomeControl();
   }

   public void DisplaySomething(String filename)
   {
     ForeignControl.DisplaySomething(filename);
     myHost.Child = ForeignControl; 
   }


}
A: 

Looks fine to me. The only thing you need to be careful about is to make sure that ForeignControl is disposed when your UserControl is finished with.

Samuel Jack