KMC
KMC

Reputation: 20036

Porting from Form to WPF

I have piece of Code in Form that works:

public class Form1 : System.Windows.Forms.Form
{
    private void Form1_Load(object sender, System.EventArgs e)
    {
       port.Parent = this;
    }
}

now I changed to WPF:

public partial class MainWindow : RibbonWindow
{
    private void Btn_Click(object sender, RoutedEventArgs e)
    {
       port.Parent = this;
    }
}

then it gives me: "Cannot implicitly convert type 'System.Windows.DependencyObject' to 'System.Windows.Forms.Control'"

What is the problem?

Upvotes: 1

Views: 1224

Answers (2)

Chen Kinnrot
Chen Kinnrot

Reputation: 21025

Because all wpf controls are sub types of DependencyObject, you can't give the parent a non DependencyObject instance, and this is the problem.

Upvotes: 1

Bas
Bas

Reputation: 27105

You are using WPF and Windows forms in one application. You cannot use a Windows Forms window as a parent for a WPF window. You should convert both Windows to WPF, or host your WPF elements in a Windows Forms ElementHost control, using a WinForms window.

Upvotes: 3

Related Questions