Share via


IXRTranslateTransform (Compact 2013)

3/28/2014

This class translates the location of an object in the two-dimensional x,y coordinate system.

Syntax

class IXRTranslateTransform : public IXRTransform

Inheritance Hierarchy

IXRDependencyObject

    IXRGeneralTransform

        IXRTransform

            IXRTranslateTransform

Methods

Method

Description

IXRTranslateTransform::GetX

Retrieves the distance to translate along the x-axis.

IXRTranslateTransform::GetY

Retrieves the distance to translate along the y-axis.

IXRTranslateTransform::SetX

Sets the distance to translate along the x-axis.

IXRTranslateTransform::SetY

Sets the distance to translate along the y-axis.

Thread Safety

Members of this class are thread-safe if you previously called IXRApplication::CreateHostFromXaml and supplied it with an XRWindowCreateParams structure that has AllowsMultipleThreadAccess set to true.

Remarks

You can offset the local origin point (0,0) for a UI element on an IXRCanvas container object by setting the attached properties Canvas.Left and Canvas.Top by calling IXRDependencyObject::SetAttachedProperty(const WCHAR*, const WCHAR*, UINT). However, this is not considered a transformation; the UI object keeps its own local origin point for transformation purposes.

You can apply a group of multiple transformations, which can also include an IXRTranslateTransform, to a UI object by using an IXRTransformGroup object. You can create custom transformations by using IXRMatrixTransform.

IXRTranslateTransform defines a translation aligned along the x-axis and y-axis. The x-coordinate of an IXRTranslateTransform indicates where the x origin point shifts to, and the y-coordinate indicates where the y origin point shifts to.

To apply a location translation for a UI object, pass this object into IXRUIElement::SetRenderTransform.

You can use transformations to alter how text is displayed in your application to create a decorative effect. For example, you can create an additional IXRTextBlock object that shadows the primary IXRTextBlock and is displayed at a slight offset to create a drop shadow effect.

When you create a class instance, use an IXRTranslateTransformPtr smart pointer instead of a raw interface pointer. For more information, see XRPtr<Interface>.

You can also define a location translation in Microsoft Silverlight 3 XAML. For information about the differences between XAML in XAML for Windows Embedded and Silverlight 3, see Differences Between Microsoft Silverlight 3 and XAML for Windows Embedded. For more information about how to define this element in the source XAML for your application, see the TranslateTransform Class on MSDN.

Example

The following code example creates two IXRRectangle objects of equal proportion, and then applies a translation transformation to one of them to produce a shadow effect.

Important

For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.

#include "windows.h"
#include "XamlRuntime.h"
#include "XRPtr.h"

void CreateShadowedRectangle(IXRApplication* pApplication, IXRCanvas* pCanvas)
{
  // Create a rectangle, a shadow rectangle, and a transformation object
  IXRRectanglePtr pPrimaryRect;
  IXRRectanglePtr pShadowRect;
  IXRTranslateTransformPtr pShadowTransform;

  pApplication->CreateObject(&pPrimaryRect);
  pApplication->CreateObject(&pShadowRect);
  pApplication->CreateObject(&pShadowTransform);

  float radiusX = 5;
  float radiusY = 5;
  float offsetX = 2;
  float offsetY = 2;

  pPrimaryRect->SetRadiusX(radiusX);
  pPrimaryRect->SetRadiusY(radiusY);

  pShadowRect->SetRadiusX(radiusX);
  pShadowRect->SetRadiusY(radiusY);

  pShadowTransform->SetX(offsetX);
  pShadowTransform->SetY(offsetY);

  // Apply the translate transformation to the shadow rectangle
  pShadowRect->SetRenderTransform((IXRTransform*)&pShadowTransform);

  IXRUIElementCollectionPtr pElementChildren;
  int indexPrimary = 0;
  int indexShadow = 1;

  // Add the two rectangles to a canvas that is in the visual tree
  pCanvas->GetChildren(&pElementChildren);
  pElementChildren->Add(pPrimaryRect, &indexPrimary);
  pElementChildren->Add(pShadowRect, &indexShadow);
}

To run this code example, you must already have created an IXRApplication instance, parsed the XAML and generated an object tree, and obtained the visual root. An IXRCanvas object must already exist in the visual tree.

.NET Framework Equivalent

System.Windows.Media.TranslateTransform

Requirements

Header

XamlRuntime.h

sysgen

SYSGEN_XAML_RUNTIME

See Also

Reference

Classes for Visual Appearance