Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XAML - Center alignment of textblock after rotation

I have a stackpanel with textblock and image. I need to align the textblock to center with rotation(90 degree).Like this,

enter image description here

But, after rotate the textblock i am always getting result like this,

enter image description here

this is the XAML code i am using,

<StackPanel Orientation="Horizontal">
        <Image Width="120" Source="ms-appx:///Assets/mail.jpg"/>
        <TextBlock Text="send mail" FontSize="15" Margin="25,0,0,0" >
            <TextBlock.RenderTransform>
                <RotateTransform Angle="90"/>
            </TextBlock.RenderTransform>
        </TextBlock>
    </StackPanel>

how can i align my textblock to center..?

like image 466
Maniarasu Avatar asked Mar 24 '23 08:03

Maniarasu


1 Answers

Setting the VerticalAlignment of the TextBlock to 'Center' and Rotating around the TextBlocks center point by setting RenderTransformOrigin should help.

<TextBlock Text="xyz" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" Margin="25,0,0,0">
    <TextBlock.RenderTransform>
        <RotateTransform Angle="90" />
    </TextBlock.RenderTransform>
</TextBlock>
like image 63
paiden Avatar answered Apr 24 '23 01:04

paiden