krizzmp 0 Posted February 1, 2010 Report Share Posted February 1, 2010 i am having this problem with c# wpf directxwhen i try to run this code vs says{Prevalence of Main Window, which is defined in the assembly Wpf3DTest, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null, can not be created. Destination of an activation triggered an exception. There is an error in markup file MainWindow.xaml, line 1, position 9"}(translated from danish using google translate)it all works fine til i set the imagebrushhere i my xaml<Window x:Class="Wpf3DTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WPF 3D Test" Height="400" Width="400"> <Grid Background="Black"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Viewport3D x:Name="viewport" Grid.Row="1"> <Viewport3D.Camera> <PerspectiveCamera x:Name="camera" FarPlaneDistance="8000" LookDirection="0,0,-10" UpDirection="0,1,0" NearPlaneDistance="0" Position="0,0,800" FieldOfView="45" /> </Viewport3D.Camera> <ModelVisual3D x:Name="model"> <ModelVisual3D.Content> <Model3DGroup x:Name="group"> <AmbientLight Color="DarkGray" /> <DirectionalLight Color="White" Direction="-5,-5,-7" /> </Model3DGroup> </ModelVisual3D.Content> </ModelVisual3D> </Viewport3D> </Grid></Window>and here is my c# codeusing 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.IO;using System.Windows.Media.Media3D;namespace Wpf3DTest { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { private GeometryModel3D mGeometry; private double thickness; private double height; private double spacing; private double width; public MainWindow() { InitializeComponent(); //double height = new double(); //double spacing = new double(); //double thickness = new double(); //double width = new double(); string folderpath; height = 80; width = 45; spacing = 2; thickness = 6; folderpath = @"D:\film\"; DirectoryInfo dir = new DirectoryInfo(folderpath); DirectoryInfo[] film = dir.GetDirectories(); MessageBox.Show(film.Count().ToString()); for (int i = 1; i <= film.Count(); i++) { if (i <= 10) { int nRow; int nColum; string nImg; nRow = 1; nColum = i; nImg = film[i].FullName + @"\front.jpg"; create_film(nRow, nColum, nImg); //MessageBox.Show(nImg); } } } private void create_film(int row,int colum,string img) { double x =new double(); double zRight = new double(); double yTop = new double(); double yBottom = new double(); double zLeft = new double(); switch (row) { case 1: yTop = 2 * height + 3 * spacing; yBottom = 1 * height + 3 * spacing; break; case 2: yTop = 1 * height + 1 * spacing; yBottom = spacing; break; case 3: yTop = (1 * height + 1 * spacing) * -1; yBottom = (0 * height + 1 * spacing) * -1; break; case 4: yTop = (2 * height + 3 * spacing) * -1; yBottom = (1 * height + 3 * spacing) * -1; break; default: break; } switch (colum) { case 1: zRight = 40; zLeft = 0; x = 0; break; case 2: zRight = 30; zLeft = 0; x = 10; goto case 1; case 3: zRight = 20; zLeft = 0; x = 20; goto case 1; case 4: zRight = 10; zLeft = 0; x = 30; goto case 1; case 5: zRight = 0; zLeft = 0; x = 0; break; case 6: zRight = 0; zLeft = 0; x = 0; goto case 1; case 7: zRight = 0; zLeft = 10; x = 150; goto case 1; case 8: zRight = 0; zLeft = 20; x = 200; goto case 1; case 9: zRight = 0; zLeft = 30; x = 250; goto case 1; case 10: zRight = 40; zLeft = 0; x = 300; goto case 1; default: break; } //zRight = 40; //zLeft = 0; //x = 0; //yTop = 2 * height + 3 * spacing; //yBottom = 1 * height + 3 * spacing; MeshGeometry3D mesh = new MeshGeometry3D(); mesh.TextureCoordinates.Add(new Point(0, 0)); mesh.TextureCoordinates.Add(new Point(0, 1)); mesh.TextureCoordinates.Add(new Point(1, 1)); mesh.TextureCoordinates.Add(new Point(1, 0)); mesh.Positions.Add(new Point3D(x, yBottom, zRight + thickness)); /* 0*/ //mesh.Normals.Add(new Vector3D(0, 0, 1)); mesh.Positions.Add(new Point3D(x + width, yBottom, zLeft + thickness)); /* 1*/ //mesh.Normals.Add(new Vector3D(0, 0, 1)); mesh.Positions.Add(new Point3D(x + width,yTop, zLeft + thickness)); /* 2*/ //mesh.Normals.Add(new Vector3D(0, 0, 1)); mesh.Positions.Add(new Point3D(x, yTop, zRight + thickness)); /* 3*/ //mesh.Normals.Add(new Vector3D(0, 0, 1)); mesh.Positions.Add(new Point3D(x, yBottom, zRight)); /* 4*/ //mesh.Normals.Add(new Vector3D(0, 0, -1)); mesh.Positions.Add(new Point3D(x + width, yBottom, zLeft)); /* 5*/ //mesh.Normals.Add(new Vector3D(0, 0, -1)); mesh.Positions.Add(new Point3D(x + width, yBottom, zLeft)); /* 6*/ //mesh.Normals.Add(new Vector3D(0, 0, -1)); mesh.Positions.Add(new Point3D(x, yTop, zRight)); /* 7*/ //mesh.Normals.Add(new Vector3D(0, 0, -1)); // Front face mesh.TriangleIndices.Add(0); mesh.TriangleIndices.Add(1); mesh.TriangleIndices.Add(2); mesh.TriangleIndices.Add(2); mesh.TriangleIndices.Add(3); mesh.TriangleIndices.Add(0); // Back face mesh.TriangleIndices.Add(6); mesh.TriangleIndices.Add(5); mesh.TriangleIndices.Add(4); mesh.TriangleIndices.Add(4); mesh.TriangleIndices.Add(7); mesh.TriangleIndices.Add(6); // Right face mesh.TriangleIndices.Add(1); mesh.TriangleIndices.Add(5); mesh.TriangleIndices.Add(2); mesh.TriangleIndices.Add(5); mesh.TriangleIndices.Add(6); mesh.TriangleIndices.Add(2); // Top face mesh.TriangleIndices.Add(2); mesh.TriangleIndices.Add(6); mesh.TriangleIndices.Add(3); mesh.TriangleIndices.Add(3); mesh.TriangleIndices.Add(6); mesh.TriangleIndices.Add(7); // Bottom face mesh.TriangleIndices.Add(5); mesh.TriangleIndices.Add(1); mesh.TriangleIndices.Add(0); mesh.TriangleIndices.Add(0); mesh.TriangleIndices.Add(4); mesh.TriangleIndices.Add(5); // Right face mesh.TriangleIndices.Add(4); mesh.TriangleIndices.Add(0); mesh.TriangleIndices.Add(3); mesh.TriangleIndices.Add(3); mesh.TriangleIndices.Add(7); mesh.TriangleIndices.Add(4); // Geometry creation ImageBrush imgbrush = new ImageBrush(); imgbrush.ImageSource = new BitmapImage(new Uri(img)); mGeometry = new GeometryModel3D(mesh, new DiffuseMaterial(imgbrush)); //mGeometry = new GeometryModel3D(mesh, new DiffuseMaterial(Brushes.Aqua)); mGeometry.Transform = new Transform3DGroup(); group.Children.Add(mGeometry); } }}any help will be apresiated (sorry for my bad spelling) i am planning on releasing the software here when im done, but bare over with me i am not that experienced as programmer as i am only 17.thx in advancekrizzmp Link to post
krizzmp 0 Posted February 2, 2010 Author Report Share Posted February 2, 2010 sorry for double posting, cant seem to find a edit button problem solved the image i was trying to load did not exist because someone deleted it Link to post
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now