簡體   English   中英

關於在windows phone中使用richtextbox的事情

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

我正在使用richtextbox在Windows Phone 7.1中顯示一些Html內容。

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>

然后我用了

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

將它們分成一個數組。 最后,我使用代碼:

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);
                }

要將一些段落或圖像添加到richtextbox中,一切進展順利,但是當我向下滾動richtextbox時,其余段落消失。 它整天困擾我,因為我無法找出richtextbox的錯誤。 這只是Windows手機中的一個錯誤嗎? 有什么想法嗎?

ScreenShot1

截圖1

ScreenShot2

截圖2

ps:html源代碼是否包含一些非英文字符並不重要。 當html源代碼包含大量單詞時會發生這種情況。 這兩個ScreenShot只顯示了這個問題。

手機應用任何UIElement在任何方向上都不能大於2048像素的限制。 這是為了避免與內存相關的性能問題並且必須繪制非常大的對象。 這是為了保護您不會做出影響性能的事情,但也有其他原因。 例如,手機是用於閱讀大量文本的不良設備。 對於密集的文本體,這尤其適用。 因此,此大小限制會強制您考慮如何或應該在應用程序中顯示大量文本。

但是有一些解決方案。
您可以考慮使用以下內容: 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