문제

enter image description hereI would like to rotate the TextBlock based on the text's center point [Horizontal and vertical). I have tried the following code. it is always taking topleft corner of the textblock. How to change it to center of the text itself.

<TextBlock Name="textBlock1"  TextWrapping="Wrap" FontSize="25" Foreground="#FFF63AFF" FontWeight="Bold"> 
TextBlock 
   <TextBlock.RenderTransform>
       <TransformGroup>
           <RotateTransform Angle="45" /> 
       </TransformGroup>   
   </TextBlock.RenderTransform>  
</TextBlock>

Image Description: Textblock is part of canvas and textblock should rotate based on the intersection as shown in the image

I have tried HorizontalAlignment as well as VerticalAlignment too, actually it is taking parent's alignment details.

Do I need to get the actual width and actual height, then based on that details calculate the center point?

도움이 되었습니까?

해결책

You need to use RenderTransformOrigin=".5,.5"

   <Grid>
        <TextBlock Name="textBlock1" RenderTransformOrigin=".5,.5"  HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap" FontSize="25" Foreground="#FFF63AFF" FontWeight="Bold"> 
            TextBlock
            <TextBlock.RenderTransform>
                <TransformGroup>
                    <RotateTransform Angle="45" />
                </TransformGroup>
            </TextBlock.RenderTransform>
        </TextBlock>
    </Grid>

Output

enter image description here

다른 팁

add the proprety in textbox :

TextAlignment="Center"

this is for horizontal alignement

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top