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);
        }

 

相关文章:

  • 2021-12-24
  • 2021-11-15
  • 2022-12-23
  • 2021-08-07
  • 2021-10-30
  • 2022-12-23
  • 2021-11-24
  • 2021-12-04
猜你喜欢
  • 2022-12-23
  • 2022-03-10
  • 2021-05-29
  • 2021-10-02
  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案