Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

TextBlock Eating Text in Windows Phone

DZone's Guide to

TextBlock Eating Text in Windows Phone

· Mobile Zone
Free Resource

Launching an app doesn’t need to be daunting. Whether you’re just getting started or need a refresher on mobile app testing best practices, this guide is your resource! Brought to you in partnership with Perfecto

I was working on an application earlier today when I ran into a serious problem.

I needed an info page with a scrollable TextBlock, because I had to add a lot of text. Obviously I started with something like that:

<ScrollViewer>
    <TextBlock />
</ScrollViewer>


But when I added my text, the result was like this:

1


My TextBlock did not display the entire text. The ScrollViewer though was working fine. I could scroll further, where the text was supposed to be.

The reason is quite simple actually. There is a 2048 pixel limitation for UI controls. For a TextBlock the way to work around is splitting the text into smaller TextBlocks and stacking them in a StackPanel.


Alex Yakhnin created a control that does this automatically. You can find it here.

In order to use that control, there are a few steps needed:

  1. Add Alex Yakhnin’s Phone.Controls project (Phone.Controls.csproj) to your solution.
  2. Add the Phone.Controls project to the References in your project.
  3. Build the Phone.Controls project.
  4. In MainPage.xaml of your project add this to the header:

    xmlns:my="clr-namespace:Phone.Controls;assembly=Phone.Controls"
  5. Now you can add a ScrollableTextBlock control to your page that just works:

2


Make sure to check out Alex Yakhnin’s Blog for more information.

 

To be continued…


Source: http://andreahaubner.blog.com/2011/11/24/textblock-eating-text/

Keep up with the latest DevTest Jargon with the latest Mobile DevTest Dictionary. Brought to you in partnership with Perfecto.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}