Search code examples
c#wpfcopyscaletransformlayouttransform

Can all of a UIElement RenderTransform effected properties be copied into a new Element?


I want to make a copy of the Element that has the new properties based upon the RenderTransform. For example, a ScaleTransform of an element on one canvas to another canvas.

private void CopyElement(UIElement elem, Canvas src, Canvas dest, Size scale, Vector offset) {
    ScaleTransform resize = new ScaleTransform(scale.Width, scale.Height);
    elem.LayoutTransform = resize;
    UIElement newElem = CopyElement(src, elem); 
    Canvas.SetLeft(newElem, Canvas.GetLeft(elem) * scale.Width + offSet.X);
    Canvas.SetTop(newElem, Canvas.GetTop(elem) * scale.Height + offSet.Y);
    dest.Children.Add(newElem);
}

Solution

  • You don't need to do this at all.

    Just set the element's LayoutTransform property instead of its RenderTransform.