Winform 中放置 ElementHost 控件加载 wpf 的 UserControl
在 WPF UserControl 中获取 winform 的方法
public partial class CrlDefinition : UserControl { public CrlDefinition() { InitializeComponent(); this.Loaded += CrlDefinition_Loaded; } void CrlDefinition_Loaded(object sender, RoutedEventArgs e) { var source = (HwndSource)PresentationSource.FromDependencyObject(this); var host = (System.Windows.Forms.Integration.ElementHost)System.Windows.Forms.Control.FromChildHandle(source.Handle); var form = (System.Windows.Forms.Form)host.TopLevelControl; // Show form title MessageBox.Show(form.Text); }