我在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, 1, 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, 1, 0), new Point3D(5, 1, 0), new Point3D(2.5, 5, 0)
};
foreach (Point3D point in points) mesh.Positions.Add(point);
Tuple<int, int, int>[] triangles =
{
new Tuple<int, int, int>(0, 1, 2)
};
foreach (Tuple<int, 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程序中执行类似操作时,它会起作用。
所以我确实有一些问题:
最诚挚的问候
Volkhard