Example #1
0
        private VisualGroup CreateVisual(CanvasControl canvas)
        {
            RectD rect = canvas.ContentRect;
            ContextConfigurator configurator = new ContextConfigurator(rect)
            {
                Margins = new InsetsD(0, 0, 0, 0)
            };

            // scale down if necessary
            if (ActualHeight > 0 && ActualHeight > 0)
            {
                if (ActualHeight < rect.Height || ActualWidth < rect.Width)
                {
                    configurator.Scale = Math.Min(ActualWidth / rect.Width, ActualHeight / rect.Height);
                }
                RectD bounds = RectD.FromCenter(rect.Center,
                                                new SizeD(ActualWidth, ActualHeight) * (1 / configurator.Scale));
                configurator.WorldBounds = bounds;
            }

            IRenderContext vc        = configurator.CreateRenderContext(canvas);
            Transform      transform = configurator.CreateWorldToIntermediateTransform();
            Visual         visual    = canvas.ExportContent(vc);

            return(new VisualGroup {
                Children = { visual }, Clip = Clip, Transform = transform
            });
        }