如何解决具有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程序中执行类似操作时,它会起作用。
所以我确实有一些问题:
- 是否可以使用ElementHost以这种方式绘制3D?
- 上面的代码有什么失败?
- 是否有相同的ccordinate-System?
最诚挚的问候
Volkhard
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。