Esempio n. 1
0
        internal static GeneralTransform TransformToScreenRoot(UIElement target)
        {
            GeneralTransform generalTransform = null;
            try
            {
                generalTransform = target.TransformToVisual(null);
            }
            catch (ArgumentException)
            {
                return new MatrixTransform { Matrix = Matrix.Identity };
            }

            var transform = generalTransform as Transform;
            if (transform == null)
            {
                var p = generalTransform.Transform(new Point(0, 0));
                return new TranslateTransform { X = p.X * ZoomFactor, Y = p.Y * ZoomFactor };
            }
            else
            {
                var group = new TransformGroup();
                group.Children.Add(transform);

                // The zoom factor is calculated automatically when the control is in a popup.
                if (target.ParentOfType<System.Windows.Controls.Primitives.Popup>() == null)
                {
                    group.Children.Add(new ScaleTransform { ScaleX = 1d / ZoomFactor, ScaleY = 1d / ZoomFactor });
                }
                else
                {
                }

                return group;
            }
        }