I´m tryng to do something like this:
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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With