简体   繁体   English

关于在windows phone中使用richtextbox的事情

[英]things on the usage of the richtextbox in windows phone

I'm using the richtextbox to show some Html content in windows phone 7.1. 我正在使用richtextbox在Windows Phone 7.1中显示一些Html内容。

The html source-code is like: html源代码如下:

Paragraph1</p>
<img src="http://www.ifanr.com/wp-content/uploads/2011/11/DSC_332401.jpg" alt="" width="600" height="338" /></p>
Paragraph2。</p>
<h3>Title h3</h3>
Paragraph3。
</p>

Then I use the 然后我用了

"string[] sArray = Regex.Split(html, "</p>", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);"

to split them into a Array. 将它们分成一个数组。 Finally, I use the code: 最后,我使用代码:

foreach (string array in sArray)
            {
                Paragraph parag = new Paragraph();
                Run run = new Run();
                Bold bold = new Bold();
                if (!Regex.IsMatch(array.ToString(), @"<img\b[^<>]*?\bsrc\s*=\s*[""']?\s*(?<imgUrl>[^\s""'<>]*)[^<>]*?/?\s*>"))
                {
                    //h3
                    if (array.ToString().Contains("</h3>"))
                    {
                        string hString = array.ToString();
                        hString = Regex.Replace(hString, "<h3>", "");
                        string[] hArray = Regex.Split(hString, "</h3>", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
                        bold.Inlines.Add(hArray[0].ToString());
                        parag.Inlines.Add(bold);
                        run.Text = hArray[1].ToString();
                        parag.Inlines.Add(run);
                    }
                    else
                    {
                        if(array.ToString().Contains("<blockquote>"))
                        {
                            run.Text = Regex.Replace(array.ToString(), "<blockquote>", "blockquote:");
                            run.FontSize = 18;
                        }
                        else
                            run.Text = array.ToString();
                        parag.Inlines.Add(run);
                    }
                    rtb.Blocks.Add(parag);
                }
                else
                {
                    //insert the image into richtextbox
                    Regex regImg = new Regex(@"http://[^\[^>]*?(gif|jpg|png|jpeg|bmp|bmp)", RegexOptions.IgnoreCase);
                    MatchCollection matches = regImg.Matches(array.ToString());
                    string result = null;
                    foreach (Match match in matches)
                        result = match.Value;

                    Image image = new Image();

                    image.Stretch = Stretch.Uniform;
                    image.Source = new BitmapImage(new Uri(result, UriKind.RelativeOrAbsolute));
                    InlineUIContainer iuc = new InlineUIContainer();
                    iuc.Child = image;
                    parag.Inlines.Add(iuc);
                    rtb.Blocks.Add(parag);
                }

to add some Paragraph or images into the richtextbox, everything goes well in the beginning, but when I Scroll down the richtextbox, the rest paragraph disappear. 要将一些段落或图像添加到richtextbox中,一切进展顺利,但是当我向下滚动richtextbox时,其余段落消失。 It confused me all day long, as I could't find out what's wrong with the richtextbox. 它整天困扰我,因为我无法找出richtextbox的错误。 Is it just a bug in Windows phone? 这只是Windows手机中的一个错误吗? Any thoughts? 有什么想法吗?

ScreenShot1 : ScreenShot1

截图1

ScreenShot2 : ScreenShot2

截图2

ps:it doesn't matter whether the html source-code contains some non-english characters or not. ps:html源代码是否包含一些非英文字符并不重要。 This happens when the html source-code is in a large amount of words. 当html源代码包含大量单词时会发生这种情况。 These two ScreenShots just show the problem. 这两个ScreenShot只显示了这个问题。

The phone applies a restriction that any UIElement can't be larger than 2048 pixels in any direction. 手机应用任何UIElement在任何方向上都不能大于2048像素的限制。 This is enforced to avoid performance issues relating to memory and having to draw very large objects. 这是为了避免与内存相关的性能问题并且必须绘制非常大的对象。 This is to protect you from doing something that greatly affects performance but also has some other reasoning behind it. 这是为了保护您不会做出影响性能的事情,但也有其他原因。 For example, a phone is a poor device for reading large pieces of text. 例如,手机是用于阅读大量文本的不良设备。 This applies even more so for dense bodies of text. 对于密集的文本体,这尤其适用。 This size restriction therefore forces you to think about how, or if you should, display large pieces of text within your application. 因此,此大小限制会强制您考虑如何或应该在应用程序中显示大量文本。

There are some solutions though. 但是有一些解决方案。
Rather than using a single Paragrpah or TextBlock for a large "unit" of text, you could consider using something like this: http://blogs.msdn.com/b/priozersk/archive/2010/09/08/creating-scrollable-textblock-for-wp7.aspx 您可以考虑使用以下内容: http//blogs.msdn.com/b/priozersk/archive/2010/09/08/creating-scrollable ,而不是将单个ParagrpahTextBlock用于大型“单元”文本。 -textblock换wp7.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM