TextBlock eating text

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:

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

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:

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

 

To be continued…

 

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: