TextBlock, RotateTransform, and Wrapping RRS feed

  • Question

  • I have a TextBlock to which I apply a RotateTransform. However, I want the text wrapping and alignment to be calculated AFTER it is rotated, not before (from what I can tell, it is calculated before rotating). Because of this, my text ends up being offset from the desired position and wrapping does not happen when I want it to. Is there any way to wait until everything else is rendered and the TextBlock is rotated before it calculates the positioning and wrapping? Here are some screenshots of what it is doing now:

    I also noticed that in previous code of mine (which was written using Visual Studio 2010 and Silverlight for Windows Phone 7) did not have this problem. Is this difference Silverlight vs Windows Runtime, Visual Studio 2010 vs Visual Studio 2013, or something else? The code is exactly the same in both:

    <TextBlock x:Name="txtCourseName" Grid.Row="2" Width="8" FontSize="1" Foreground="White" IsHitTestVisible="False" TextWrapping="Wrap" TextAlignment="Center" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Center" VerticalAlignment="Center" Text="My Favorite Golf Course">
    	<TextBlock.RenderTransform><CompositeTransform Rotation="90" ScaleX="24" ScaleY="24"/></TextBlock.RenderTransform>
    Any help would be appreciated. Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Thursday, January 22, 2015 2:28 AM

All replies

  • Something that I just noticed (which I think is very strange) is that when scrolling, this element of my layout continuously changes in the designer. Not just refreshing (I have seen plenty of times where scrolling refreshes the designer), but changes it, then changes it to something else, then something else, etc. This makes me wonder whether it is the designer or the code (or both), but the inconsistency of the designer makes it hard to tell without running the actual app. Has anybody else seen anything like this? I'm probably just going to wait until the rest of my app is finished so that I can see what happens while testing the other stuff, but I still find the inconsistency very strange.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Thursday, January 22, 2015 5:03 PM
  • If I understand you correctly, then this should point you in the right direction:

    <StackPanel Orientation="Horizontal">
        <TextBlock Background="Red" Text="My Title">
                    <RotateTransform Angle="90"/>

    The key is to use LayoutTransform, not RenderTransform. This will ensure that another layout pass occurs after the transform occurs. Otherwise, the layout system is using the original bounding rectangle to layout the TextBlock.

    Vote if help you

    Friday, January 23, 2015 10:05 AM
  • Thank you for your response, it sounds like it will solve my problem, but I am having trouble finding LayoutTransform. It is not listed in the Properties window or Intellisense. I know that LayoutTransform is unavailable for Silverlight, but my project is Windows Phone 8.1, NOT Silverlight. Why does Visual Studio 2013 say that LayoutTransform is not there? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Friday, January 23, 2015 4:31 PM
  • I recently found this posting, which says that LayoutTransform is not supported in Windows.UI.Xaml:


    However, the following 2 documentation pages say that it is available in System.Windows & System.Windows.Controls:



    I noticed that the posting that says it is not available mentions Windows.UI.Xaml, while the documentation refers to System.Windows & System.Windows.Controls. I think that, if I am correct, this means I cannot use it here. But the idea of doing a second layout pass after the transform sounds like a step in the right direction if there is a way to call it manually. Is there any way to call it manually (I'm assuming using the UpdateLayout() method) after the first pass? I'm not sure where I would put that code that makes sure it happens after the first pass. Any ideas? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Friday, January 23, 2015 5:39 PM