具有WPF的WinForm Elementhost不显示§d图形

问题描述

我在winform上确实有以下代码

using System;
using System.Windows.Forms;
using System.Windows.Forms.Integration;

using wpf = System.Windows.Controls;
using wpfpaint = System.Windows.Media;
using System.Windows.Media.Media3D;

namespace WindowsForms_WPF_3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            FormBorderStyle = FormBorderStyle.Fixed3D;
            
            // Elemethost für wpf-Control definieren

            ElementHost eh = new ElementHost();
            eh.Dock = DockStyle.Fill;
            this.Controls.Add(eh);


            //wpf-Control DockPanel definieren und der Eigenschaft child des Elementhost zuordnen

            wpf.DockPanel dp = new wpf.DockPanel();
            dp.Background = wpfpaint.Brushes.LightGray;
            eh.Child = dp;


            // wpf-Viewport3D Element für die Anzeige von 3D-Gfrafiken definieren

            wpf.Viewport3D vp3d = new wpf.Viewport3D();


            // ...

            wpfpaint.Media3D.ModelVisual3D visual3d = new wpfpaint.Media3D.ModelVisual3D();
            wpfpaint.Media3D.Model3DGroup group3d = new wpfpaint.Media3D.Model3DGroup();

            visual3d.Content = group3d;
            vp3d.Children.Add(visual3d);


            // Kamera definieren

            Point3D position = new Point3D(1,-1,15);
            Vector3D lookDirection = new Vector3D(1,1,0);
            Vector3D upDirection = new Vector3D(0,0);
            double fieldOfView = 45;
            PerspectiveCamera camera = new PerspectiveCamera(position,lookDirection,upDirection,fieldOfView);

            vp3d.Camera = camera;

            // Licht definieren

            group3d.Children.Add(new AmbientLight(wpfpaint.Colors.LightGreen));
            Vector3D direction = new Vector3D(1,-2,-3);
            group3d.Children.Add(new DirectionalLight(wpfpaint.Colors.LightSalmon,direction));

            // Modell definieren

            MeshGeometry3D mesh = new MeshGeometry3D();
            Point3D[] points =
            {
                new Point3D(1,0),new Point3D(5,new Point3D(2.5,5,0)
            };

            foreach (Point3D point in points) mesh.Positions.Add(point);

            Tuple<int,int,int>[] triangles =
            {
                 new Tuple<int,int>(0,2)
            };

            foreach (Tuple<int,int> tuple in triangles)
            {
                mesh.TriangleIndices.Add(tuple.Item1);
                mesh.TriangleIndices.Add(tuple.Item2);
                mesh.TriangleIndices.Add(tuple.Item3);
            }

            // Objektmaterial definieren

            DiffuseMaterial material = new DiffuseMaterial(wpfpaint.Brushes.LightBlue);

            // Modell kreieren

            GeometryModel3D model = new GeometryModel3D(mesh,material);


            // Modell der Geometriegruppe zuweisen

            group3d.Children.Add(model);

            // wpf DockPanel zum Viewport 3D einfügen

            dp.Children.Add(vp3d);

        }
    }
}

我希望它显示一个多维数据集,但不会显示-当我在wpf程序中执行类似操作时,它会起作用。

所以我确实有一些问题:

  1. 是否可以使用ElementHost以这种方式绘制3D?
  2. 上面的代码有什么失败?
  3. 是否有相同的ccordinate-System

最诚挚的问候

Volkhard

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...