Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Rotate text

Tags:

rotation

wpf

I´m tryng to do something like this:

enter image description here

I have a List with my own object, in this List I have all the information to draw it, I have a Listbox and every figure is an item of Listbox that I draw in a position of the canvas.

My problem is when I want to draw the Name, becuase I have to rotate the name and to draw it inside of the rectangle of the name, but when I rotate the name I don´t know how to draw it inside de rectangle.

I´m using this datatemplate for my listbox ItemTemplate, I put visibility depending on if I want to draw the image or name.

<DataTemplate x:Key="templateList">
    <Canvas >
        <WrapPanel 
                  Visibility="{Binding IsStone, Converter={StaticResource converterCheckIsVisibleName}}"
                  Width="{Binding ObjectName.Width}"
                  Height="{Binding ObjectName.Height}">

                <TextBlock Text="{Binding ObjectName.Name}" >
                    <TextBlock.RenderTransform>
                        <RotateTransform Angle="{Binding ObjectName.Rotate}" />
                    </TextBlock.RenderTransform>
                </TextBlock>
            </WrapPanel>


           <Border BorderThickness="1"  BorderBrush="Black" 
                        Visibility="{Binding IsStone, Converter={StaticResource converterCheckIsVisibleStone}}">
                    <Image Source="{Binding ObjectIMG.PathImagen}" 
                           Height="{Binding ObjectIMG.Height}"
                           Width="{Binding ObjectIMG.Width}"
                           Stretch="Fill" />
                </Border>

            </Canvas>                                        
        </DataTemplate>
like image 446
user1253414 Avatar asked Jan 08 '14 11:01

user1253414


1 Answers

I'm not 100% sure what your problem is, but it seems as though you just want to rotate some text and put it into a rectangle. The Rectangle class does not take a content element, so you can't use that, but you can use a simple Border element.

One other thing to notice is that you should probably use the LayoutTransform which occurs before the layout pass, as opposed to the RenderTransform which is applied afterwards. See the FrameworkElement.LayoutTransform Property page on MSDN for more information on this. Try something like this:

<Border BorderBrush="Black" BorderThickness="5">
    <TextBlock Text="{Binding ObjectName.Name}" >
        <TextBlock.LayoutTransform>
            <RotateTransform Angle="{Binding ObjectName.Rotate}" />
        </TextBlock.LayoutTransform>
    </TextBlock>
</Border>
like image 113
Sheridan Avatar answered Nov 18 '22 10:11

Sheridan