我已经在 WPF 中创建了一个 .DLL。要在现有 Windows 窗体应用程序中使用它,我使用 ElementHost
。
ElementHost eleHOst = new ElementHost();
UserWarps userWarps = new UserWarps();
eleHOst.Child = userWarps;
eleHOst.Dock = DockStyle.Fill;
UserWarps
位于 WPF .DLL
中,已添加引用。现在文件做了很多 3D 操作。我还使用 Petzold.Media3D
为 3D 线
进行线框建模。一切正常,除了 Petzold.Media3D
的 WireLines
没有绘制任何线条。如果我从其他 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/