Export (0) Print
Expand All

TranslateTransform Class

Translates (moves) an object in the 2-D x-y coordinate system.

Namespace: System.Windows.Media
Assembly: PresentationCore (in presentationcore.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public sealed class TranslateTransform : Transform
public final class TranslateTransform extends Transform
public final class TranslateTransform extends Transform
<TranslateTransform .../>

TranslateTransform defines an axis-aligned translation along the x- and y- axes. The following illustration shows the transformation matrix for a translation by offset (dx, dy).

Typical 3x3 matrix for 2-D translations


Freezable Features: Because it inherits from the Freezable class, the TranslateTransform class provides several special features: TranslateTransform objects can be declared as resources, shared among multiple objects, made read-only to improve performance, cloned, and made thread-safe. For more information about the different features provided by Freezable objects, see Freezable Objects Overview.

This example shows how to translate (move) an element by using a TranslateTransform.

The TranslateTransform class is especially useful for moving elements inside panels that do not support absolute positioning. For example, by applying a TranslateTransform to the RenderTransform property of an element, you can move an element within a StackPanel or DockPanel.

Use the X property of the TranslateTransform to specify the amount, in pixels, to move the element along the x-axis. Use the Y property to specify the amount, in pixels, to move the element along the y-axis. Finally, apply the TranslateTransform to the RenderTransform property of the element.

The following example uses a TranslateTransform to move an element 50 pixels to the right and 50 pixels down.

<Rectangle Height="50" Width="50" 
  Fill="#CCCCCCFF" Stroke="Blue" StrokeThickness="2"
  Canvas.Left="100" Canvas.Top="100">
  <Rectangle.RenderTransform>
    <TranslateTransform X="50" Y="50" />
  </Rectangle.RenderTransform>
</Rectangle>

For the complete sample, see 2-D Transforms Sample.

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Freezable
         System.Windows.Media.Animation.Animatable
           System.Windows.Media.GeneralTransform
             System.Windows.Media.Transform
              System.Windows.Media.TranslateTransform

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft