Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this questionI 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
This seems to be quite a common question.
I recommend:
- Take a look at the Kindle app - it's free and Amazon have built a good app
- Here's some analysis of how Kindle might work - What's the control used in Kindle for Windows Phone 7 and Programmatically determining max fit in textbox (WP7)
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.
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.
精彩评论