TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Volkhard Vogeler
NA
11
1.8k
WinForm Elementhost with WPF doesn´t show 3d Graphic
Aug 11 2020 12:14 PM
Hello,
i do have following Code on a 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);
}
}
}
I expect that it Shows a cube but it doesn´t - When i do the simular thing within an wpf-program it works.
So i do have some Questions:
1) It is possible to use ElementHost to draw 3Ds in this way?
2) what is the failure in the Code above?
3) Is there the same ccordinate-System?
best regards
Volkhard
Reply
Answers (
2
)
rdlc report without preview not working in setup file
Passing data from 2 forms to same textbox c#