CompositionTarget.Render and ZoomExtents

Nov 1, 2013 at 6:43 PM
Hello,

This is probably a trivial problem, but I'm new to C# and WPF, and I've been scratching my head for some time now.
I'm using a CompositionTarget.Render, such that I can disable and re-enable some parts of the rendering (think I got this from the Points and Lines example).

Before I got all this to work, I used the Loaded += MainWindow_Loaded like in a lot of the examples. This included the ZoomExtents. A neat little feature.

I would like to know how I can incorporate this with the Compositiontarget.Render.

Some code below.
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            CompositionTarget.Rendering += this.OnCompositionTargetRendering;            
       }
        void OnCompositionTargetRendering(object sender, EventArgs e)
        {

            if (ShowEdges && lines == null)
            {
                lines = new LinesVisual3D { Color = Colors.Red };
                view.Children.Add(lines);
            }
            if (!ShowEdges && lines != null)
            {
                lines.IsRendering = false;
                view.Children.Remove(lines);
                lines = null;
            }
            if (ShowFaceNormals && faceNormals == null)
            {
                faceNormals = new LinesVisual3D {Color = Colors.Purple};
                view.Children.Add(faceNormals);
            }
            if (!ShowFaceNormals && faceNormals != null)
            {
                faceNormals.IsRendering = false;
                view.Children.Remove(faceNormals);
                faceNormals = null;
            }
            if (ShowFaces && faces==null)
            {
                faces = new ModelVisual3D
                {
                    Content = new GeometryModel3D
                    {
                        Material = Materials.Red,
                        BackMaterial = Materials.Blue
                    }
                };

                view.Children.Add(faces);
            }
            if (!ShowFaces && faces != null)
            {
                view.Children.Remove(faces);
                faces = null;
            }

            if (lines != null)
            {
                createWireframe();
            }
            if (faceNormals != null)
            {
                createFaceNormals();
            }
            if (faces != null)
            {
                createFaces();
            }
        }