0

I am trying to simulate the experience of reading a book in WP7. I basically have text I need to display in a textblock, enough to fill the page and allow the user to flip to the next page by swiping the finger across the screen. I am running into a few issues and I'd like to see if anyone has come across this or has a better idea:

  • the text I have is much longer than what I can fit on a single page, so I need to put only enough text in the textblock, font size and style are variable so I cannot build fixed pages. Any idea on how to truncate the text at the right length? Everything I could come up with is fairly computational intensive, e.g. add words and measure the textblock until it exceeds a preset size, then paint it
  • wp7 textblock lacks support for text justification, so I was wondering if anybody came across good WPF/SL/WP7 techniques for justifying text with variable char width

right now I am looking into having a series of textblocks, one line tall, one after the other in a stackpanel, enough to fill the screen and individually justified, hopefully not too resource intensive.

I will let you know what I find.

thank you

skaffman
  • 398,947
  • 96
  • 818
  • 769

2 Answers2

0

For pagination - Stuart has very nice answer here. Solution seems to be in in-code textblock for measuring.

Justification - I didn't care about it, so nothing on that part.

Community
  • 1
  • 1
jumbo
  • 4,670
  • 5
  • 39
  • 44
0

This seems to be quite a common question.

I recommend:

On your proposal, I think using multiple <Run>s inside a single multiline <TextBlock> is pretty much the same resource usage as putting multiple lines on a single page - so your approach should be OK.

Community
  • 1
  • 1
Stuart
  • 66,722
  • 7
  • 114
  • 165
  • Got it. I went with the `Run` approach and was able to have it pretty much working in a couple of hours. The tricky part is keeping track of the different text pointers when moving back and forth. +/-1 make all the difference in the world! :-) If people are interested I can offer more detail. I'll post a sample to my blog when I get the chance. – Roberto Ruggeri Mar 21 '11 at 05:39