.Net: How to use a WPF user control in a windows forms application?
How to use a WPF user control in a windows 开发者_运维知识库forms application?
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".
精彩评论