How to use a WPF user control in a windows forms application?
+3
A:
From the MSDN:
Use the ElementHost control to place a WPF UIElement on your Windows Forms control or form.
Example:
private void Form1_Load(object sender, EventArgs e)
{
// Create the ElementHost control for hosting the
// WPF UserControl.
ElementHost host = new ElementHost();
host.Dock = DockStyle.Fill;
// Create the WPF UserControl.
HostingWpfUserControlInWf.UserControl1 uc =
new HostingWpfUserControlInWf.UserControl1();
// Assign the WPF UserControl to the ElementHost control's
// Child property.
host.Child = uc;
// Add the ElementHost control to the form's
// collection of child controls.
this.Controls.Add(host);
}
Here is a nice tutorial how to do that.
The control called ElementHost is for WPF in WinForms what the WindowsFormsHost was for WinForms in WPF. In the designer, you can find this control in the Toolbox underneath "WPF Interoperability".
mafutrct
2010-05-19 12:47:11
It would help to quote some of the relevant information from the linked to page. You don't have to (nor should you) copy it all, but we need to know whether it's worth clicking on the link.
ChrisF
2010-05-19 12:49:35
Indeed, thanks for the hint!
mafutrct
2010-05-19 12:54:45