如何在 winforms usercontrol 中添加 wpf usercontrol ?尝试使用元素主机托管Wpf用户控件,如下所示。添加的子控件不会在设计和运行时显示。
public partial class WinformsUC: UserControl
{
public WinformsUC()
{
InitializeComponent();
try
{
var eH = new ElementHost {Dock = DockStyle.Fill, Child = new WpfUserControl()};
Controls.Add(eH);
}
catch (Exception exception)
{
Log.Debug(Constructor : " + exception.Message);
}
}
}
答案 0 :(得分:0)
你可以使用system.windows.forms.integration.elementhost
来做到这一点示例:
private ElementHost ctrlHost;
private UIElement wpfUserControl;
// in the from the load event handler
ctrlHost = new ElementHost();
ctrlHost.Dock = DockStyle.Fill;
panel1.Controls.Add(ctrlHost);
wpfUserControl= new WpfUserControl();
//we need to manually call initializecomponent if it is not called
//in the constructor of your control
wpfUserControl.InitializeComponent();
ctrlHost.Child = wpfInputControl;