Skip to main content

Microsoft Silverlight

Answered Question Rotated TextBlock - text is cut before rotationRSS Feed

(0)

VladF
VladF

Member

Member

216 points

87 Posts

Rotated TextBlock - text is cut before rotation

I created a TextBlock with several words of text. I set a fixed Width for it and applied RotateTransform to it as a render transform. The entire text is longer than the assigned width, but TextBlock is rotated 90 degrees and rotated text should fit pretty well vertically (there is no limitation on height). Unfortunatelly only the first word is shown: I suppose it happened because of an optimization to not display invisible text. The problem is that this check was done before render transform was applied and text was rotated. If I remove the Width limitation the entire text will be visible after rotation.

See the sample XAML:

<Canvas x:Name="parentCanvas"

xmlns="http://schemas.microsoft.com/client/2007"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Loaded="Page_Loaded"

x:Class="SilverlightProject24.Page;assembly=ClientBin/SilverlightProject24.dll"

Width="640"

Height="480"

Background="White"

>

<
TextBlock Width="55" Text="111111 222222222 3333333" FontSize="30">

<TextBlock.RenderTransform>

<TransformGroup>

<RotateTransform Angle="90"/>

<TranslateTransform X="55"/>

</TransformGroup>

</TextBlock.RenderTransform>

</TextBlock>

</Canvas>

y_makram
y_makram

Contributor

Contributor

6172 points

1,233 Posts

Re: Rotated TextBlock - text is cut before rotation

I believe that you are confused here. Applying a 90 degree rotate transform on an object does not mean that the width and height of the object will change. 2D and 3D transforms are generally done by multiplying the coordinates of the object by a special matrix. SO transformations does not change the properties of the affected object. TranslateTransform will not change the left and top properties of the object. ScaleTransform will not change the width and height properties of the object. So if fore example a rectangle with 100 width is scaled by double, its width property will not be 200, it will still be 100, and you will need to perform math calculations to get the actual width.

Thanks
Yasser Makram
http://www.silverlightrecipes.com
_____
Dont forget to click "Mark as Answer" on the post that helped you. If your question has not been answered, please post a followup question.

VladF
VladF

Member

Member

216 points

87 Posts

Re: Re: Rotated TextBlock - text is cut before rotation

Did you take a look at the XAML I provided? I'm not talking about the not rotated width, I'm talking about clipped text. I know that render transform won't change the dimenstions - it is a RENDER transfrom after all. But TextBlock makes assumption about how much text should be visible and this assumption seems to be wrong for me in this case.

y_makram
y_makram

Contributor

Contributor

6172 points

1,233 Posts

Re: Re: Rotated TextBlock - text is cut before rotation

I am not sure that I understand the bug you are posting. I have tried your XAML code and it is behaving normally to me. You have specified the width of the textblock to 55, and Silverlight trims the text to the specified width. When removing the width property, the text is fully displayed. 

Thanks
Yasser Makram
http://www.silverlightrecipes.com
_____
Dont forget to click "Mark as Answer" on the post that helped you. If your question has not been answered, please post a followup question.

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Re: Rotated TextBlock - text is cut before rotation

Hello, since you’ve rotated the TextBlock for 90 degrees, its Width will appear to be Height. Try to remove the rotation, you’ll notice the same, only the first word is displayed. This is because you have a Width limit set on the TextBlock, and keeps its default TextWrapping value, which is NoWrap. If you set TextWrapping to Wrap, you’ll probably get the result you want.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

VladF
VladF

Member

Member

216 points

87 Posts

Re: Re: Rotated TextBlock - text is cut before rotation

Do I understand correctly that clipping of the text is happening before the TextBlock is rotated?

y_makram
y_makram

Contributor

Contributor

6172 points

1,233 Posts

Re: Re: Rotated TextBlock - text is cut before rotation

Not sure of the sequence. But rotating the text will not affect the clipping, only width, height wordwrap, clip, and opacitymask properties will affect the textblock clipping.

Thanks
Yasser Makram
http://www.silverlightrecipes.com
_____
Dont forget to click "Mark as Answer" on the post that helped you. If your question has not been answered, please post a followup question.

VladF
VladF

Member

Member

216 points

87 Posts

Re: Re: Re: Rotated TextBlock - text is cut before rotation

1) Why 2 posts in this thread were marked as answers? I did not mark them.

2) I don't think there is a clear explanation here. What is happening seems to be an optimization and it does not work very well. Here is another example

<Canvas x:Name="parentCanvas"

xmlns="http://schemas.microsoft.com/client/2007"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Loaded="Page_Loaded"

x:Class="SilverlightProject25.Page;assembly=ClientBin/SilverlightProject25.dll"

Width="640"

Height="480"

Background="White"

>

<
Rectangle Width="200" Height="100" Fill="Orange"/>

<TextBlock x:Name="TB" Width="200" Height="100" TextWrapping="NoWrap">

111111111111 222222222222222 333333333333333 4444444444444444 55555555555555555 666666666666666 777777777777777777 888888888888888 99999999999999</TextBlock>

</Canvas>

When you run project with this XAML you will see that 2 first words are shown and visible text is much wider than its set Width. If you say that Width should clip text why it does not clip it in this case? All this looks like "soft" clipping: TextBlock does not clip words, it clips phrases only. Is it a bug or a feature?

Mark Rideout
Mark Rid...

Contributor

Contributor

2357 points

273 Posts

MicrosoftModerator
Answered Question

Re: Re: Re: Rotated TextBlock - text is cut before rotation

Silverlight 2 TextBlock will stop processing characters at the next word break if that word break is outside the bounds of the TextBlock's Width. In Silverlight all clipping is off by default. When the layout system was added we added layout enforced clipping. Canvas element does not participate in this layout enforced clipping.

Hope this helps,
-mark
Silverlight Text Program Manager
Microsoft
This post is provided "as-is"

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities