Вопрос

I understand I can rotate text like this:

<TextBlock Text="4:00">
    <TextBlock.RenderTransform>
        <RotateTransform Angle="-90"/>
    </TextBlock.RenderTransform>
</TextBlock>

But how can I use the RenderTransform property of TextBlock directly like:

<TextBlock Text="4:00" RenderTransform="<How does this work?>"/>

to avoid the inner code? Maybe a general tutorial for how this works would be good as well.

Это было полезно?

Решение

RenderTransform property is of type Transform which can mean many possible transform types. So you can`t assign it to some type that has some properties using just a string by default. If you want to to conserve space though, you can define your RotateTransform in resources, and give it some key:

<Window.Resources>
    <RotateTransform x:Key="myRotateTransform" Angle="-90" />
</Window.Resources>

Then just use it like that:

<TextBlock Text="4:00" RenderTransform="{StaticResource myRotateTransform}" />

This will work even better if you need to apply same transform to several controls too, because you can edit it in just one place.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top