【问题标题】:Error with adding WPF user control to ElementHost in Windows Form在 Windows 窗体中将 WPF 用户控件添加到 ElementHost 时出错
【发布时间】:2015-02-20 15:16:45
【问题描述】:

我正在尝试将 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。我还应该做什么?

【问题讨论】:

  • 我认为这会有所帮助 > stackoverflow.com/questions/4874495/…
  • @safi:感谢那篇文章。它有很大帮助。我只是使用了 WPF 窗口,而不是 WPF 用户控件。现在效果很好。所以它在我的 MainForm 顶部的指定位置打开。有没有办法将它锚定到 MainForm 的边缘?我知道这是一个窗口,所以可能不是直接的,但是有没有可能的解决方法?

标签: wpf vb.net winforms user-controls


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-11
    相关资源
    最近更新 更多