How to add WPF controller to a Winform dinamically??
-
Hello evveryone, I am trying to add my WPF controller to a winform dynamically. Could anyone please help me? This is what I tried so fare
MyWinForm myForm = new MyWinForm();
WpfUserControl uc = new WpfUserControl();if (ListBox.SelectedItem != null) { WPFObject selObject = Listbox.SelectedItem as WPFObject; uc.GetObjects(selObject); **myForm.Controls.Add(uc);** myForm.Visible = true; }
it throws an error. cannot convert WpfUsercontrol to System.Windows.Forms.Control. Is there a way to add WPF controller dynamic to a winform?? many thanks in advance!
-
Hello evveryone, I am trying to add my WPF controller to a winform dynamically. Could anyone please help me? This is what I tried so fare
MyWinForm myForm = new MyWinForm();
WpfUserControl uc = new WpfUserControl();if (ListBox.SelectedItem != null) { WPFObject selObject = Listbox.SelectedItem as WPFObject; uc.GetObjects(selObject); **myForm.Controls.Add(uc);** myForm.Visible = true; }
it throws an error. cannot convert WpfUsercontrol to System.Windows.Forms.Control. Is there a way to add WPF controller dynamic to a winform?? many thanks in advance!
You cannot directly use a WPF control in WinForms. You will need to use an ElementHost[^] e.g.
ElementHost elhost = new ElementHost(); elhost.Size = new Size(110, 60); elhost.Location = new Point(45,35); MyWPFControl wpfctl = new MyWPFControl(); elhost.Child = wpfctl; myForm.Controls.Add(elhost);
See here[^] -
You cannot directly use a WPF control in WinForms. You will need to use an ElementHost[^] e.g.
ElementHost elhost = new ElementHost(); elhost.Size = new Size(110, 60); elhost.Location = new Point(45,35); MyWPFControl wpfctl = new MyWPFControl(); elhost.Child = wpfctl; myForm.Controls.Add(elhost);
See here[^]