Exemple #1
0
        private Rect ComputeBounds(Viewport3D viewport)
        {
            double x = 0;
            double y = 0;
            Window w = FindContainingWindow(viewport);

            if (w != null)
            {
                // NOTE! Any changes made to viewport.RenderTransform will not be reflected by TransformToAncestor
                // until you re-render the viewport with that new RenderTransform.  Composition team says it's by design.

                GeneralTransform gt = viewport.TransformToAncestor(w);
                Point            p  = gt.Transform(new Point(0, 0));

                // Because of the above behavior, we must manually undo the RenderTransform
                //  because we don't want to factor in the RenderTransform just yet.
                // It is handled like an effect at the end of the rendering pass.
                if (viewport.RenderTransform != null)
                {
                    p = viewport.RenderTransform.Inverse.Transform(p);
                }
                x = p.X;
                y = p.Y;
            }
            double width  = MathEx.FallbackIfNaN(viewport.Width, viewport.ActualWidth);
            double height = MathEx.FallbackIfNaN(viewport.Height, viewport.ActualHeight);

            return(new Rect(x, y, width, height));
        }