Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Windows窗体中将WPF用户控件添加到ElementHost时出错_Wpf_Vb.net_Winforms_User Controls - Fatal编程技术网

在Windows窗体中将WPF用户控件添加到ElementHost时出错

在Windows窗体中将WPF用户控件添加到ElementHost时出错,wpf,vb.net,winforms,user-controls,Wpf,Vb.net,Winforms,User Controls,我正在尝试将WPF用户控件添加到windows窗体。WPF用户控件目前没有任何内容,但我将添加按钮。在表单加载中,我执行以下操作: Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load SetStyle(ControlStyles.SupportsTransparentBackColor, True) Application.EnableVisualStyles() Di

我正在尝试将WPF用户控件添加到windows窗体。WPF用户控件目前没有任何内容,但我将添加按钮。在表单加载中,我执行以下操作:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    SetStyle(ControlStyles.SupportsTransparentBackColor, True)
    Application.EnableVisualStyles()

    Dim elemHost As New ElementHost
    Dim wuc As WPFUC = New WPFUC

    elemHost.Controls.Add(wuc)    <<-- I get error here
    'elemHost.child = wuc    <<-- and here
    AddSolid()
    'AddPanel()
End Sub

错误是WindowsApplication1.WPFUC类型的值无法转换为System.Windows.Forms.Control。我还应该做什么?

我只是使用PointToScreen方法计算了屏幕点,并将其指定为我需要的WPF窗口的位置。

我认为这会很有帮助>@safi:谢谢你的文章。这很有帮助。我只是使用了一个WPF窗口,而不是WPF用户控件。现在它工作得很好。因此,它会在我的主窗体顶部的指定位置打开。有没有办法把它固定在主窗体的边缘?我知道这是一个窗口,所以可能不是直接的,但是有可能的解决办法吗?