4

Currently, I'm showing a really long text inside a RichTextBlock inside a ScrollViewer.

The problem is since ScrollViewer doesn't support virtualization, loading the page takes a few seconds, and changing font size (it's an option for the user) takes a long time and may even cause the app to crash.

One solution came to my mind is to break RichTextBlock to a number of RichTextBlocks inside a ListView (which supports Virtualization).

But this approach has a little problem. Let's say I show each 500 lines of text inside a RichTextBlock. Now, the user may want to select and copy some text; while it'll work well in most cases, but he'll never be able to select lines 498 to 503, because they are in two separate RichTextBlocks.

Is there any way to fix the text selection issue in this approach? Or can you suggest a better way for implementing virtualization?

Mahdi Ghiasi
  • 14,873
  • 19
  • 71
  • 119
  • The most reliable solution would be to find a new way to present the data that doesn't involve a scroll viewer containing other scrollviewer controls (like the rich text edit). – WiredPrairie Aug 16 '15 at 11:37
  • @WiredPrairie `RichTextBlock` doesn't have a `ScrollViewer` inside it. – Mahdi Ghiasi Aug 18 '15 at 10:14
  • The `RichTextBox` does ... which is what I thought you meant when I read your question. :) Honestly, this problem has come up many times in the last few years as the tech you're using is originally based on Silverlight, which had the same issue. There's never been a particularly satisfying solution other than to design a different user experience where this can't be an issue. – WiredPrairie Aug 18 '15 at 14:09
  • @WiredPrairie I was thinking about using a `RichEditBox` instead, but seems that it doesn't support xaml text and I have to create it in plan (*scary/ugly*) rtf. Am I missing something? – Mahdi Ghiasi Aug 18 '15 at 17:38
  • What kind of content do you have? – WiredPrairie Aug 18 '15 at 22:15
  • @WiredPrairie Some Persian poetry. it's just normal text but text alignment might be different in different verses (left, right, center), also I might want to add a margin from left or right to some of centered verses too. – Mahdi Ghiasi Aug 19 '15 at 20:44
  • You might want to consider embedding a WebView and inject the content as HTML. You can't put it in a scroll viewer though (as the webview is height limited and performs poorly and uses a **lot** of system resources if it exceeds screen height). – WiredPrairie Aug 20 '15 at 00:50
  • @WiredPrairie That was what I tried first, but experienced issues with handling swiping. Although then I replaced those with a `Pivot` later (after switching to `RickTextBlock`). And now I checked and it seems swiping a `WebView` inside `Pivot` works fine. Maybe I'll consider switching back to HTML method. And I don't need to put it inside a `ScrollViewer`. WebView has something like `ScrollViewer` inside it afterall. Thanks :) – Mahdi Ghiasi Aug 20 '15 at 08:40
  • @WiredPrairie I just saw that `WebView` doesn't work well with a `Pivot` on the phone. (it's ok on touch PC but not in phone). So using `WebView` is not an option unfortunately :( – Mahdi Ghiasi Aug 20 '15 at 08:55
  • did you find the solution? – Maryam Aug 22 '16 at 06:14
  • @Maryam Unfortunately no. At last I used the approach described in the question and ignored that little problem with it. – Mahdi Ghiasi Aug 22 '16 at 20:50

0 Answers0