public LandscapeGeneratorSample()
        {
            InitializeComponent();


            // Setup RadioBoxes and Comboboxes
            FillPossibleLandscapeSizes();

            // Create linear gradient that will be used for Legent and for coloring vertexes
            var linearGradientBrush = CreateDataGradientBrush();

            _gradientColor4Array = CreateGradientColorsArray(linearGradientBrush);

            AddLegendControl(linearGradientBrush);


            // Adjust the CameraAxis control to show a coordinate system with Z up (more standard when showing height map).
            // Note: WPF uses right handed coordinate system with Y up.
            CameraAxisPanel1.CustomizeAxes(new Vector3D(1, 0, 0), "X", Colors.Red,
                                           new Vector3D(0, 1, 0), "Z", Colors.Green,
                                           new Vector3D(0, 0, -1), "Y", Colors.Blue);


            Camera1.StartRotation(10, 0);

            this.Loaded += delegate(object sender, RoutedEventArgs args)
            {
                GoToNextRandomSeed(); // Set new random seed - after seed text will be changed, the CreateLandscape will be called
            };

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                if (_vertexColorMaterial != null)
                {
                    _vertexColorMaterial.Dispose();
                }

                MainDXViewportView.Dispose();
            };
        }
        public VertexColorRenderingSample()
        {
            InitializeComponent();

            AddTestModel();

            Camera1.StartRotation(45, 0);


            // Cleanup
            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                // We need to dispose all DXEngine objects that are created here - in this case _vertexColorMaterial
                if (_vertexColorMaterial != null)
                {
                    _vertexColorMaterial.Dispose();
                    _vertexColorMaterial = null;
                }

                MainDXViewportView.Dispose();
            };
        }
        public VertexColorRenderingSample()
        {
            InitializeComponent();

            CreateGradientColorsArray();

            // Use CameraControllerInfo to show that we can use left mouse button to set custom beam destination on the 3D model
            CameraControllerInfo.AddCustomInfoLine(0, MouseCameraController.MouseAndKeyboardConditions.LeftMouseButtonPressed, "SET BEAM DESTINATION");

            // When the ViewportBorder size is change the size of the overlay Canvas (drawn over the 3D scene)
            ViewportBorder.SizeChanged += delegate(object sender, SizeChangedEventArgs args)
            {
                UpdateOverlayCanvasSize();
            };


            // Process mouse events
            ViewportBorder.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e)
            {
                // Start user beam control
                _isUserBeamControl = true;

                ViewportBorder.CaptureMouse();

                var position = e.GetPosition(ViewportBorder);
                ProcessMouseHit(position);
            };

            ViewportBorder.MouseLeftButtonUp += delegate(object sender, MouseButtonEventArgs e)
            {
                // Stop user beam control
                _isUserBeamControl = false;
                ViewportBorder.ReleaseMouseCapture();

                ProcessMouseOutOfModel();
            };

            // Subscribe to MouseMove to allow user to specify the beam target
            ViewportBorder.MouseMove += delegate(object sender, MouseEventArgs e)
            {
                if (_isUserBeamControl)
                {
                    ProcessMouseHit(e.GetPosition(ViewportBorder));
                }
                else
                {
                    ProcessMouseOutOfModel();
                }
            };


            // Start animating the beam position
            CompositionTarget.Rendering += CompositionTargetOnRendering;


            // We add test models after the DXScene is initialized (this is required because specifal effects require DirectX device)
            MainDXViewportView.DXSceneInitialized += delegate(object sender, EventArgs e)
            {
                if (MainDXViewportView.DXScene == null)
                {
                    return; // Probably WPF 3D rendering
                }
                // Get _vertexColorEffect that will be used to render model with vertex colors (note that this field must be disposed when it is not used any more - here in Unloaded event handler)

                AddTestModels();
            };

            // Cleanup
            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                CompositionTarget.Rendering -= CompositionTargetOnRendering;

                if (_vertexColorMaterial != null)
                {
                    _vertexColorMaterial.Dispose();
                    _vertexColorMaterial = null;
                }

                if (_lineMaterial != null)
                {
                    _lineMaterial.Dispose();
                    _lineMaterial = null;
                }

                MainDXViewportView.Dispose();
            };
        }