Compartilhar via


Como: Inverter horizontalmente ou verticalmente um UIElement

This example shows how to use a ScaleTransform to flip a UIElement horizontally or vertically. In this example, a Button control (a type of UIElement) is flipped by applying a ScaleTransform to its RenderTransform property.

Exemplo

The following illustration shows the button to flip.

The UIElement to flip

Um botão sem transformação

The following shows the code that creates the button.

<Button Content="Flip me!" Padding="5">
</Button>

Para inverter o botão horizontalmente, criar um ScaleTransform e defina seu ScaleX a propriedade como -1. Aplicar o ScaleTransform do botão RenderTransform propriedade.

<Button Content="Flip me!" Padding="5">
  <Button.RenderTransform>
    <ScaleTransform ScaleX="-1" />
  </Button.RenderTransform>
</Button>

The button after applying the ScaleTransform

Um botão invertido horizontalmente ao redor do ponto (0,0)

As you can see from the previous illustration, the button was flipped, but it was also moved. That's because the button was flipped from its top left corner. To flip the button in place, you want to apply the ScaleTransform to its center, not its corner. An easy way to apply the ScaleTransform to the buttons center is to set the button's RenderTransformOrigin property to 0.5, 0.5.

<Button Content="Flip me!" Padding="5"
  RenderTransformOrigin="0.5,0.5">
  <Button.RenderTransform>
    <ScaleTransform ScaleX="-1" />
  </Button.RenderTransform>
</Button>

The button with a RenderTransformOrigin of 0.5, 0.5

Um botão invertido horizontalmente ao redor de seu centro

To flip the button vertically, set the ScaleTransform object's ScaleY property instead of its ScaleX property.

<Button Content="Flip me!" Padding="5"
  RenderTransformOrigin="0.5,0.5">
  <Button.RenderTransform>
    <ScaleTransform ScaleY="-1" />
  </Button.RenderTransform>
</Button>

The vertically flipped button

Um botão invertido verticalmente ao redor de seu centro

Consulte também

Conceitos

Visão Geral sobre Transformações