c# - 在 Windows 窗体中托管 WPF 时出现问题 - C#

标签 c# .net wpf windows winforms

我已经在 WPF 中创建了一个 .DLL。要在现有 Windows 窗体应用程序中使用它,我使用 ElementHost

ElementHost eleHOst = new ElementHost();
UserWarps userWarps = new UserWarps();
eleHOst.Child = userWarps;
eleHOst.Dock = DockStyle.Fill;

UserWarps 位于 WPF .DLL 中,已添加引用。现在文件做了很多 3D 操作。我还使用 Petzold.Media3D3D 线 进行线框建模。一切正常,除了 Petzold.Media3DWireLines 没有绘制任何线条。如果我从其他 WPF 应用程序引用 DLL,一切都很好,但是在 Windows 窗体中托管 wpf 的 UserControl 消除了线条/线框。休息一切都是完美的 - MeshGeometry3D,模型,视觉效果,功能等。

请提出前进的方向。 ElementHost 的替代方案是否可行?如果是,那是什么?

最佳答案

Adding answer originally added by OP in question as I don't want this question to be closed just because of that.

Petzold 提到了 here在 Windows 窗体中托管 wpf 会导致线框消失。他还发布了一个非常简单且工作完美的解决方法:

NOTE: For reasons discussed in paragraph 5, these Wire classes will not work when you're hosting 3D in Windows Forms, or when you're trying to print a 3D scene. To make it work, try replacing the static OnRendering method in WireBase with the following:

static void OnRendering(object sender, EventArgs args)
{
    foreach (WireBaseAndUltimateParent wirebaseAndParent in listWireBases)
    {
        WireBase wirebase = wirebaseAndParent.wirebase;
        wirebase.OnRendering();
    }
}

关于c# - 在 Windows 窗体中托管 WPF 时出现问题 - C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13452268/

相关文章:

c# - 为什么有些文化默认将货币小数点四舍五入?

.net - Dotnetnuke版本确定

c# - Linq 根据存储在 SQL 中的字符串返回单个整数值

c# - KeyNotFoundException 信息

c# - 如何在 asp.net mvc 2 中进行整数模型验证

c# - 如何在一个案例中处理多个值?

c# - 正确显示 BusyIndi​​cator

wpf - 使用XAML完成Storyboard时将元素的可见性设置为“折叠”

c# - 绘制控件到内存(位图)

c# - 如何使用 CodeDOM 初始化对象?