how to reference the parent form from the WPF control(Control in ElementHost)

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);
        }
----------------------------------- http://www.cnblogs.com/rock_chen/
原文地址:https://www.cnblogs.com/rock_chen/p/2978313.html