当添加Xaml代码来投影wpf窗口时,将不会加载

时间:2018-10-20 10:41:10

标签: c# wpf

我有一个带有Helix Toolkit的WPF应用程序,当前可加载3D模型以显示在窗口上。

从我添加到xaml文件的那一刻起,它就不会再启动了,并且也不会出现错误。

<Window x:Class="fyssim.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:fyssim"
    xmlns:h="http://helix-toolkit.org/wpf"
    xmlns:HelixToolkit="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">

没有网格的XAML代码

 public MainWindow()
    {
        InitializeComponent();
        Create3DViewPort();
        device3D.Content = Display3d(MODEL_PATH);
        // Add to view port
        ViewPort.Children.Add(device3D);

        RotateModel();
    }

    private void Create3DViewPort()
    {
        var lights = new DefaultLights();
        var teaPot = new Teapot();
        ViewPort.Children.Add(lights);
        this.AddChild(ViewPort);
        ViewPort.LookAt(new Point3D(0, 0, 2));
    }

    private Model3D Display3d(string model)
    {
        Model3DGroup device = null;
        try
        {
            Console.WriteLine("Hello!!!");
            ViewPort.RotateGesture = new MouseGesture(MouseAction.LeftClick);
            ModelImporter import = new ModelImporter();
            device = import.Load(model);
        }
        catch (Exception e)
        {
            MessageBox.Show("Exception Error : " + e.StackTrace);
        }
        return device;
    }

    private void RotateModel()
    {
        var axis = new Vector3D(1, 0, 0);
        var angle = 90;

        var matrix = device3D.Transform.Value;
        matrix.Rotate(new Quaternion(axis, angle));

        device3D.Transform = new MatrixTransform3D(matrix);
    }

导入模型的c#代码

希望你能帮助我。

0 个答案:

没有答案