Bonjour,

Je suis nouveau dans le monde du développement C# et du développement 3D, Je viens de construire mon premier cube 3D dans une class que j'ai appelé MyCube.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Media3D;
using System.Windows.Media.Animation;
using WpfApplication3.Properties;
 
namespace WpfApplication3
{
    class MyCube
    {
 
        Viewport3D Viewport = new Viewport3D(); //Viewport3D class provides a rendering surface for 3-D visual content
        GeometryModel3D surface1 = new GeometryModel3D();//GeometryModel3D class object provides generalized transformation support for 3-D objects
        GeometryModel3D surface2 = new GeometryModel3D();
        GeometryModel3D surface3 = new GeometryModel3D();
        GeometryModel3D surface4 = new GeometryModel3D();
        GeometryModel3D surface5 = new GeometryModel3D();
        GeometryModel3D surface6 = new GeometryModel3D();
 
        //adding for test
        GeometryModel3D text1 = new GeometryModel3D();
        MeshGeometry3D text1plane = new MeshGeometry3D();
        DiffuseMaterial surface1Materialtext1 = new DiffuseMaterial();
 
        PerspectiveCamera Camera = new PerspectiveCamera();//PerspectiveCamera class object represents a perspective projection camera
 
        DirectionalLight myDLight = new DirectionalLight();//DirectionalLight class object provides effect along a direction
        DirectionalLight myDLight2 = new DirectionalLight();
        AmbientLight AmLight = new AmbientLight();//AmbientLight class objects provides Lights every surface uniformly a bright AmbientLight creates  because of lack of shading, but a low-intensity AmbientLight approximatesthe effect of light that has been scattered by reflecting between diffuse surfaces in the scene.
 
        MaterialGroup myMaterials = new MaterialGroup();//MaterialGroup class objects applies multiple Materials to a model each Material is rendered in order, with the last Material in the group appearing on top.
        Transform3DGroup Transgroup = new Transform3DGroup();//Transform3DGroup class contains a collection of Transform3Ds.
        Model3DGroup Modelgroup = new Model3DGroup();//The Model3DGroup class is itself a Model3D and is often used to group multiple GeometryModel3Ds
        Model3DGroup cube = new Model3DGroup();
        MeshGeometry3D surface1Plane = new MeshGeometry3D();// MeshGeometry3D class represents a set of 3D surfaces
        MeshGeometry3D surface2Plane = new MeshGeometry3D();
        MeshGeometry3D surface3Plane = new MeshGeometry3D();
        MeshGeometry3D surface4Plane = new MeshGeometry3D();
        MeshGeometry3D surface5Plane = new MeshGeometry3D();
        MeshGeometry3D surface6Plane = new MeshGeometry3D();
        DiffuseMaterial surface1Material = new DiffuseMaterial();//DiffuseMaterial class provides scatters light striking the surface in all directions,
        DiffuseMaterial surface2Material = new DiffuseMaterial();
        DiffuseMaterial surface3Material = new DiffuseMaterial();
        DiffuseMaterial surface4Material = new DiffuseMaterial();
        DiffuseMaterial surface5Material = new DiffuseMaterial();
        DiffuseMaterial surface6Material = new DiffuseMaterial();
        ModelVisual3D ModelVisualD = new ModelVisual3D();//ModelVisual3D class contains 3-D models
        TextBlock textBlock = new TextBlock();
        //Name of the image
 
        ImageBrush imageBrushFace1; 
        ImageBrush imageBrushFace2;
        ImageBrush imageBrushFace3;
        ImageBrush imageBrushFace4;
        ImageBrush imageBrushFace5;
        ImageBrush imageBrushFace6;
 
 
 
        public MyCube(ImageBrush imageBrushFace1, ImageBrush imageBrushFace2, ImageBrush imageBrushFace3, ImageBrush imageBrushFace4, ImageBrush imageBrushFace5, ImageBrush imageBrushFace6)
        {
 
            this.imageBrushFace1 = imageBrushFace1;
            this.imageBrushFace2 = imageBrushFace2;
            this.imageBrushFace3 = imageBrushFace3;
            this.imageBrushFace4 = imageBrushFace4;
            this.imageBrushFace5 = imageBrushFace5;
            this.imageBrushFace6 = imageBrushFace6;
 
        }
 
 
 
 
 
        public Viewport3D createMyCube()
        {
 
            Camera.Position = new Point3D(0, 0, 4);
            Camera.LookDirection = new Vector3D(0, 0, -1);
            Camera.UpDirection = new Vector3D(0, 1, 0);
            Camera.FieldOfView = Convert.ToDouble(50);
            //setting the color of light
            AmLight.Color = Colors.White;
 
            text1.Geometry = text1plane;
            surface1.Geometry = surface1Plane;
            surface2.Geometry = surface2Plane;
            surface3.Geometry = surface3Plane;
            surface4.Geometry = surface4Plane;
            surface5.Geometry = surface5Plane;
            surface6.Geometry = surface6Plane;
 
            Vector3D vecD = new Vector3D(-50, -90, 0);
 
            Rotation3D RD = new AxisAngleRotation3D(vecD, 1);
 
            RotateTransform3D RotateTrans = new RotateTransform3D(RD);//RotateTransform3D class specify rotation transformation that is parameterized
 
            //Define an animation for the rotation
 
            DoubleAnimation myAnimation = new DoubleAnimation();
            myAnimation.From = 1;
            myAnimation.To = 361;
            myAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(5000));//Defining time in second for cube that will be rotate
            myAnimation.RepeatBehavior = RepeatBehavior.Forever;
            RotateTrans.Rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, myAnimation);
 
            //Add transformation to the model
 
            Transgroup.Children.Add(RotateTrans);
 
            cube.Children.Add(surface1);
            cube.Children.Add(surface2);
            cube.Children.Add(surface3);
            cube.Children.Add(surface4);
            cube.Children.Add(surface5);
            cube.Children.Add(surface6);
 
 
            Modelgroup.Transform = Transgroup;
 
            //Create directional Light effects
            myDLight.Color = Colors.White;
            myDLight.Direction = new Vector3D(-0.612372, -0.5, -0.612372);
            //Create directional Light effects
            //       myDLight2.Color = Colors.White;
            //  myDLight2.Direction = new Vector3D(-0.612372, -0.5, -0.612372);
 
            //myDLight2.Direction = new Vector3D(0.612372, -0.5, -0.612372);
 
 
 
 
            Modelgroup.Children.Add(cube);
            Modelgroup.Children.Add(text1);
            Modelgroup.Children.Add(myDLight);
            //  Modelgroup.Children.Add(myDLight2);
            Modelgroup.Children.Add(AmLight);
 
            Viewport.Camera = Camera;
 
            //   ModelVisualD.Content = myDLight;
 
            //ModelVisualD.Content = myDLight2;
 
            ModelVisualD.Content = Modelgroup;
 
 
            Viewport.Children.Add(ModelVisualD);
            //Defining surface position in world coordinate
 
            text1plane.Positions.Add(new Point3D(4, 4, -5));
            text1plane.Positions.Add(new Point3D(3.5,-3.5, -3.5));
            text1plane.Positions.Add(new Point3D(4, 4, -5));
            text1plane.Positions.Add(new Point3D(4, 4, -5));
            text1plane.Positions.Add(new Point3D(4, 4, -5));
            text1plane.Positions.Add(new Point3D(4, 4, -5));
            text1plane.TriangleIndices.Add(0);
            text1plane.TriangleIndices.Add(1);
            text1plane.TriangleIndices.Add(0);
            text1plane.TriangleIndices.Add(0);
            text1plane.TriangleIndices.Add(0);
            text1plane.Normals.Add(new Vector3D(0, 0, -6));
            text1plane.Normals.Add(new Vector3D(0, 0, -5));
            text1.Material = new DiffuseMaterial(imageBrushFace1);
 
 
 
 
            //Defining surface position in world coordinates
            //-----------------------surface1------------------------
            surface1Plane.Positions.Add(new Point3D(0.5, 0.5, -0.5));
            surface1Plane.Positions.Add(new Point3D(0.5, -0.5, -0.5));
            surface1Plane.Positions.Add(new Point3D(-0.5, -0.5, -0.5));
            surface1Plane.Positions.Add(new Point3D(-0.5, -0.5, -0.5));
            surface1Plane.Positions.Add(new Point3D(-0.5, 0.5, -0.5));
            surface1Plane.Positions.Add(new Point3D(0.5, 0.5, -0.5));
 
 
 
            //TriangleIndices—Describes the connections between the vertices to form triangles if TriangleIndices is not specified, it is implied that the positions should beconnected in the order they appear: 0 1 2, then 3 4 5, and so on.
            surface1Plane.TriangleIndices.Add(0);
            surface1Plane.TriangleIndices.Add(1);
            surface1Plane.TriangleIndices.Add(2);
            surface1Plane.TriangleIndices.Add(3);
            surface1Plane.TriangleIndices.Add(4);
            surface1Plane.TriangleIndices.Add(5);
 
            surface1Plane.Normals.Add(new Vector3D(0, 0, -1));
            surface1Plane.Normals.Add(new Vector3D(0, 0, -1));
            surface1Plane.Normals.Add(new Vector3D(0, 0, -1));
            surface1Plane.Normals.Add(new Vector3D(0, 0, -1));
            surface1Plane.Normals.Add(new Vector3D(0, 0, -1));
            surface1Plane.Normals.Add(new Vector3D(0, 0, -1));
 
            surface1Plane.TextureCoordinates.Add(new Point(1, 0));
            surface1Plane.TextureCoordinates.Add(new Point(1, 1));
            surface1Plane.TextureCoordinates.Add(new Point(0, 1));
            surface1Plane.TextureCoordinates.Add(new Point(0, 1));
            surface1Plane.TextureCoordinates.Add(new Point(0, 0));
            surface1Plane.TextureCoordinates.Add(new Point(1, 0));
 
            //-----------------------surface2------------------------
 
            surface2Plane.Positions.Add(new Point3D(0.5, 0.5, 0.5));
            surface2Plane.Positions.Add(new Point3D(-0.5, 0.5, 0.5));
            surface2Plane.Positions.Add(new Point3D(-0.5, -0.5, 0.5));
            surface2Plane.Positions.Add(new Point3D(-0.5, -0.5, 0.5));
            surface2Plane.Positions.Add(new Point3D(0.5, -0.5, 0.5));
            surface2Plane.Positions.Add(new Point3D(0.5, 0.5, 0.5));
 
 
            surface2Plane.TriangleIndices.Add(0);
            surface2Plane.TriangleIndices.Add(1);
            surface2Plane.TriangleIndices.Add(2);
            surface2Plane.TriangleIndices.Add(3);
            surface2Plane.TriangleIndices.Add(4);
            surface2Plane.TriangleIndices.Add(5);
 
            surface2Plane.Normals.Add(new Vector3D(0, 0, 1));
            surface2Plane.Normals.Add(new Vector3D(0, 0, 1));
            surface2Plane.Normals.Add(new Vector3D(0, 0, 1));
            surface2Plane.Normals.Add(new Vector3D(0, 0, 1));
            surface2Plane.Normals.Add(new Vector3D(0, 0, 1));
            surface2Plane.Normals.Add(new Vector3D(0, 0, 1));
 
            surface2Plane.TextureCoordinates.Add(new Point(0, 0));
            surface2Plane.TextureCoordinates.Add(new Point(1, 0));
            surface2Plane.TextureCoordinates.Add(new Point(1, 1));
            surface2Plane.TextureCoordinates.Add(new Point(1, 1));
            surface2Plane.TextureCoordinates.Add(new Point(0, 1));
            surface2Plane.TextureCoordinates.Add(new Point(0, 0));
 
            //-----------------------surface3------------------------
 
            surface3Plane.Positions.Add(new Point3D(0.5, -0.5, 0.5));
            surface3Plane.Positions.Add(new Point3D(-0.5, -0.5, 0.5));
            surface3Plane.Positions.Add(new Point3D(-0.5, -0.5, -0.5));
            surface3Plane.Positions.Add(new Point3D(-0.5, -0.5, -0.5));
            surface3Plane.Positions.Add(new Point3D(0.5, -0.5, -0.5));
            surface3Plane.Positions.Add(new Point3D(0.5, -0.5, 0.5));
 
 
            surface3Plane.TriangleIndices.Add(0);
            surface3Plane.TriangleIndices.Add(1);
            surface3Plane.TriangleIndices.Add(2);
            surface3Plane.TriangleIndices.Add(3);
            surface3Plane.TriangleIndices.Add(4);
            surface3Plane.TriangleIndices.Add(5);
 
            surface3Plane.Normals.Add(new Vector3D(0, -1, 0));
            surface3Plane.Normals.Add(new Vector3D(0, -1, 0));
            surface3Plane.Normals.Add(new Vector3D(0, -1, 0));
            surface3Plane.Normals.Add(new Vector3D(0, -1, 0));
            surface3Plane.Normals.Add(new Vector3D(0, -1, 0));
            surface3Plane.Normals.Add(new Vector3D(0, -1, 0));
 
            surface3Plane.TextureCoordinates.Add(new Point(0, 0));
            surface3Plane.TextureCoordinates.Add(new Point(1, 0));
            surface3Plane.TextureCoordinates.Add(new Point(1, 1));
            surface3Plane.TextureCoordinates.Add(new Point(1, 1));
            surface3Plane.TextureCoordinates.Add(new Point(0, 1));
            surface3Plane.TextureCoordinates.Add(new Point(0, 0));
 
            //-----------------------surface4------------------------
 
            surface4Plane.Positions.Add(new Point3D(0.5, 0.5, 0.5));
            surface4Plane.Positions.Add(new Point3D(0.5, -0.5, 0.5));
            surface4Plane.Positions.Add(new Point3D(0.5, -0.5, -0.5));
            surface4Plane.Positions.Add(new Point3D(0.5, -0.5, -0.5));
            surface4Plane.Positions.Add(new Point3D(0.5, 0.5, -0.5));
            surface4Plane.Positions.Add(new Point3D(0.5, 0.5, 0.5));
 
 
            surface4Plane.TriangleIndices.Add(0);
            surface4Plane.TriangleIndices.Add(1);
            surface4Plane.TriangleIndices.Add(2);
            surface4Plane.TriangleIndices.Add(3);
            surface4Plane.TriangleIndices.Add(4);
            surface4Plane.TriangleIndices.Add(5);
 
            surface4Plane.Normals.Add(new Vector3D(1, 0, 0));
            surface4Plane.Normals.Add(new Vector3D(1, 0, 0));
            surface4Plane.Normals.Add(new Vector3D(1, 0, 0));
            surface4Plane.Normals.Add(new Vector3D(1, 0, 0));
            surface4Plane.Normals.Add(new Vector3D(1, 0, 0));
            surface4Plane.Normals.Add(new Vector3D(1, 0, 0));
 
            surface4Plane.TextureCoordinates.Add(new Point(1, 0));
            surface4Plane.TextureCoordinates.Add(new Point(1, 1));
            surface4Plane.TextureCoordinates.Add(new Point(0, 1));
            surface4Plane.TextureCoordinates.Add(new Point(0, 1));
            surface4Plane.TextureCoordinates.Add(new Point(0, 0));
            surface4Plane.TextureCoordinates.Add(new Point(1, 0));
 
            // -----------------------surface5------------------------
 
            surface5Plane.Positions.Add(new Point3D(-0.5, 0.5, 0.5));
            surface5Plane.Positions.Add(new Point3D(0.5, 0.5, 0.5));
            surface5Plane.Positions.Add(new Point3D(0.5, 0.5, -0.5));
            surface5Plane.Positions.Add(new Point3D(0.5, 0.5, -0.5));
            surface5Plane.Positions.Add(new Point3D(-0.5, 0.5, -0.5));
            surface5Plane.Positions.Add(new Point3D(-0.5, 0.5, 0.5));
 
            surface5Plane.TriangleIndices.Add(0);
            surface5Plane.TriangleIndices.Add(1);
            surface5Plane.TriangleIndices.Add(2);
            surface5Plane.TriangleIndices.Add(3);
            surface5Plane.TriangleIndices.Add(4);
            surface5Plane.TriangleIndices.Add(5);
 
            surface5Plane.Normals.Add(new Vector3D(0, 1, 0));
            surface5Plane.Normals.Add(new Vector3D(0, 1, 0));
            surface5Plane.Normals.Add(new Vector3D(0, 1, 0));
            surface5Plane.Normals.Add(new Vector3D(0, 1, 0));
            surface5Plane.Normals.Add(new Vector3D(0, 1, 0));
            surface5Plane.Normals.Add(new Vector3D(0, 1, 0));
 
            surface5Plane.TextureCoordinates.Add(new Point(1, 1));
            surface5Plane.TextureCoordinates.Add(new Point(0, 1));
            surface5Plane.TextureCoordinates.Add(new Point(0, 0));
            surface5Plane.TextureCoordinates.Add(new Point(0, 0));
            surface5Plane.TextureCoordinates.Add(new Point(1, 0));
            surface5Plane.TextureCoordinates.Add(new Point(1, 1));
 
            // -----------------------surface6------------------------
 
            surface6Plane.Positions.Add(new Point3D(-0.5, -0.5, 0.5));
            surface6Plane.Positions.Add(new Point3D(-0.5, 0.5, 0.5));
            surface6Plane.Positions.Add(new Point3D(-0.5, 0.5, -0.5));
            surface6Plane.Positions.Add(new Point3D(-0.5, 0.5, -0.5));
            surface6Plane.Positions.Add(new Point3D(-0.5, -0.5, -0.5));
            surface6Plane.Positions.Add(new Point3D(-0.5, -0.5, 0.5));
 
 
            surface6Plane.TriangleIndices.Add(0);
            surface6Plane.TriangleIndices.Add(1);
            surface6Plane.TriangleIndices.Add(2);
            surface6Plane.TriangleIndices.Add(3);
            surface6Plane.TriangleIndices.Add(4);
            surface6Plane.TriangleIndices.Add(5);
 
            surface6Plane.Normals.Add(new Vector3D(-1, 0, 0));
            surface6Plane.Normals.Add(new Vector3D(-1, 0, 0));
            surface6Plane.Normals.Add(new Vector3D(-1, 0, 0));
            surface6Plane.Normals.Add(new Vector3D(-1, 0, 0));
            surface6Plane.Normals.Add(new Vector3D(-1, 0, 0));
            surface6Plane.Normals.Add(new Vector3D(-1, 0, 0));
 
            surface6Plane.TextureCoordinates.Add(new Point(0, 1));
            surface6Plane.TextureCoordinates.Add(new Point(0, 0));
            surface6Plane.TextureCoordinates.Add(new Point(1, 0));
            surface6Plane.TextureCoordinates.Add(new Point(1, 0));
            surface6Plane.TextureCoordinates.Add(new Point(1, 1));
            surface6Plane.TextureCoordinates.Add(new Point(0, 1));
 
            //Accessing ImageBrush tags from App.xaml file with their keys name
 
            DiffuseMaterial surface1Material = new DiffuseMaterial(imageBrushFace1);
            DiffuseMaterial surface2Material = new DiffuseMaterial(imageBrushFace1);
            DiffuseMaterial surface3Material = new DiffuseMaterial(imageBrushFace1);
            DiffuseMaterial surface4Material = new DiffuseMaterial(imageBrushFace1);
            DiffuseMaterial surface5Material = new DiffuseMaterial(imageBrushFace1);
            DiffuseMaterial surface6Material = new DiffuseMaterial(imageBrushFace1);
 
            //DiffuseMaterial surface1Material = new DiffuseMaterial((Brush)Application.Current.Resources[ImageName1]);
            //DiffuseMaterial surface2Material = new DiffuseMaterial((Brush)Application.Current.Resources[ImageName2]);
            //DiffuseMaterial surface3Material = new DiffuseMaterial((Brush)Application.Current.Resources[ImageName3]);
            //DiffuseMaterial surface4Material = new DiffuseMaterial((Brush)Application.Current.Resources[ImageName4]);
            //DiffuseMaterial surface5Material = new DiffuseMaterial((Brush)Application.Current.Resources[ImageName5]);
            //DiffuseMaterial surface6Material = new DiffuseMaterial((Brush)Application.Current.Resources[ImageName6]);
 
 
            surface2.Material = surface2Material;
            surface6.Material = surface6Material;
            surface1.Material = surface1Material;
            surface3.Material = surface3Material;
            surface4.Material = surface4Material;
            surface5.Material = surface5Material;
            //mainWindow.Content = Viewport;
 
            return Viewport;
        }
 
 
    }
}
Cette classe renvoie un viewport 3D, et j' affiche mon composant dans ma fenêtre comme cela :


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 public MainWindow()
        {
            InitializeComponent();
 
            //Create 3Dcube
  MyCube mycube = new MyCube(imagebrush, imagebrush, imagebrush, imagebrush, imagebrush, imagebrush);
 
            mainWindow.Content = mycube.createMyCube();
 
        }
Mais une fois que j'essai de mettre mon cube dans un canvas ou dans un stackPanel ou bien un élément de type Grid mon cube ne s'affiche plus.

mon code est le suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
  public StackPanel addingStackPanel(Viewport3D viewport)
        {
 
            // Create a StackPanel and Add children
            StackPanel myStackPanel = new StackPanel();
            myStackPanel.Orientation = Orientation.Horizontal;
 
            Border myBorder1 = new Border();
            myBorder1.Width = 100;
            myBorder1.Height = 50;
            TextBlock txt1 = new TextBlock();
            txt1.Foreground = Brushes.White;
            txt1.FontSize = 16;
            txt1.Text = "Stacked Item #1";
            myBorder1.Child = txt1;
 
            Border myBorder2 = new Border();
            myBorder2.Width = 150;
            myBorder2.Height = 50;
            TextBlock txt2 = new TextBlock();
            txt2.Foreground = Brushes.White;
            txt2.FontSize = 16;
            txt2.Text = "Stacked Item #2";
            myBorder2.Child = txt2;
 
            Border myBorder3 = new Border();
            myBorder3.BorderBrush = Brushes.Black;
            //myBorder3.
            myBorder3.Width = 150;
            myBorder2.Height = 100;
            TextBlock txt3 = new TextBlock();
            txt3.Foreground = Brushes.White;
            txt3.FontSize = 16;
            txt3.Text = "Stacked Item #3";
            myBorder3.Child = txt3;
 
            // Add the Borders to the StackPanel Children Collection
 
 
           mystackpanel.Children.Add(viewport);
            mystackpanel.Children.Add(myBorder1);
            myStackPanel.Children.Add(myBorder2);
            myStackPanel.Children.Add(myBorder3);
 
            return mystackpanel;
        }
et la j'affiche mon StackPanel en faisant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
public MainWindow()
        {
            InitializeComponent();
 
            //Create 3Dcube
  MyCube mycube = new MyCube(imagebrush, imagebrush, imagebrush, imagebrush, imagebrush, imagebrush);
 
            mainWindow.Content = addingStackPanel(viewport);
 
        }
Et la quand j'essai d'afficher mon stack panel mon cube 3D n'apparait plus.
J'ai testé avec le composant grid et canvas même résultat le cube ne s'affiche pas.
Quelqu'un à t-il une idée du pourquoi ?


Cordialement