TrueTransform Class |
Namespace: Ab2d.Utility.ReaderWmf
public class TrueTransform
The TrueTransform type exposes the following members.
Name | Description | |
---|---|---|
TrueTransform | Initializes a new instance of the TrueTransform class |
Name | Description | |
---|---|---|
Transform(Panel, Transform) |
Transforms the coordinats, sizes and other values in the originalElement with using transformation.
| |
Transform(Viewbox, Transform) |
Transforms the coordinats, sizes and other values in the originalGeometry with using transformation.
| |
Transform(Geometry, Transform) |
Transforms the coordinats, sizes and other values in the originalGeometry with using transformation.
| |
Transform(Shape, Transform) |
Transforms the coordinats, sizes and other values in the originalShape with using transformation.
|
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.
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