带有WPF UserControl的WinForms,它显示了另一个窗口

时间:2016-04-04 09:54:58

标签: c# wpf winforms xaml user-controls

我在WinForms和WPF中遇到输入互操作问题。

的Winforms / C#:

UserControlDLL.MyUserControl userControl = new UserControlDLL.MyUserControl();

public Form1()
{
    InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
    userControl.ShowTextBox();
}

WPF:

public partial class MyUserControl : UserControl
{
    internal static DisplayWindow display;

    public MyUserControl()
    {
        InitializeComponent();
        display = new DisplayWindow();
    }
}

当userControl创建新的DisplayWindow时,我无法在DisplayWindow的文本框中输入任何内容。

1 个答案:

答案 0 :(得分:1)

尝试this

public Form1()
{
    InitializeComponent();

    ElementHost host= new ElementHost();
    host.Size = new Size(200, 100);
    host.Location = new Point(100,100);

    UserControlDLL.MyUserControl edit = new UserControlDLL.MyUserControl();
    host.Child = edit;

    this.Controls.Add(host);
}