Click or drag to resize
TrueTransform Class
TrueTransform class can be used to transfrom the coordinates, sizes and other values in the original WPF element and create a new WPF element with transformed values.
Inheritance Hierarchy
SystemObject
  Ab2d.Utility.ReaderWmfTrueTransform

Namespace: Ab2d.Utility.ReaderWmf
Assembly: Ab2d.ReaderWmf (in Ab2d.ReaderWmf.dll) Version: 7.1.5512.1040
Syntax
C#
public class TrueTransform

The TrueTransform type exposes the following members.

Constructors
  NameDescription
Public methodTrueTransform
Initializes a new instance of the TrueTransform class
Top
Methods
  NameDescription
Public methodStatic memberTransform(Panel, Transform)
Transforms the coordinats, sizes and other values in the originalElement with using transformation.
Public methodStatic memberTransform(Viewbox, Transform)
Transforms the coordinats, sizes and other values in the originalGeometry with using transformation.
Public methodStatic memberTransform(Geometry, Transform)
Transforms the coordinats, sizes and other values in the originalGeometry with using transformation.
Public methodStatic memberTransform(Shape, Transform)
Transforms the coordinats, sizes and other values in the originalShape with using transformation.
Top
Remarks

TrueTransform class can be used to transfrom the coordinates, sizes and other values in the original WPF element and create a new WPF element with transformed values.

In WPF the transormations are usually applied with setting a Transform property on a shape or other element. This transform the object coordinates, sizes and other values before the object representation is sent to graphics card. This is done behind the scene. But if we want to transform the object and get transformed object without using Transform property we can use the TrueTransform.

For example if we have:
<Rectangle Canvas.Left="100" Canvas.Top="50" Width="200" Height="300" />
and send it to Transform(Shape, Transform) method with transformation parameter set to ScaleTransform with ScaleX = ScaleY = 0.5, we get back:
<Rectangle Canvas.Left="50" Canvas.Top="25" Width="100" Height="150" />

With using different version of Transform methods it is possible to transform objects that are derived from:
- Panel (for example Canvas)
- Shape (for example Rectangle, Ellipse)
- Geometry (for example DrawingGeometry).

Note that TrueTransform is primarily used to transform shapes and not common GUI elements like Buttons, TextBoxes, etc - therefore it cannot transform all possible WPF elements.

Examples

The following code can be used to translate and scale the objects read with ReaderSvg:

var readViewbox = Ab2d.ReaderSvg.Instance.Read("mySvgFile.svg");

// First get the inner canvas - this way we skip the size adjustments
var rootCanvas = _lastSvgViewbox.Child as Canvas;

if (rootCanvas == null || rootCanvas.Children.Count == 0)
    return;

var innerCanvas = rootCanvas.Children[0] as Canvas;

if (innerCanvas == null)
    return;

// Create transformation (note that order of adding transformations to TransformGroup is important)
var transformGroup = new TransformGroup();
transformGroup.Children.Add(new TranslateTransform(100, 100));
transformGroup.Children.Add(new ScaleTransform(0.5, 0.5));

// Create transformed objects
var transformedCanvas = Ab2d.Utility.ReaderSvg.TrueTransform.Transform(innerCanvas, transformGroup) as Canvas; // when using ReaderWmf use the Ab2d.Utility.ReaderWmf namespace
See Also