【发布时间】:2012-01-02 22:56:41
【问题描述】:
我正在使用 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时,其余段落消失了。它整天让我感到困惑,因为我无法找出富文本框有什么问题。 它只是Windows手机中的一个错误吗?有什么想法吗?
ScreenShot1:
ScreenShot2:
ps:html源代码是否包含一些非英文字符都没有关系。当 html 源代码包含大量单词时,就会发生这种情况。这两张截图正好说明了问题。
【问题讨论】:
-
您应该使用英文字符来举例说明您的代码。如果我们甚至可以通过字符读取您的代码,那么很难为您提供帮助。
标签: c# html windows-phone-7 richtextbox