ell*_*lic 3 html c# richtextbox windows-phone-7
我正在使用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>
Run Code Online (Sandbox Code Playgroud)
然后我用了
"string[] sArray = Regex.Split(html, "</p>", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);"
Run Code Online (Sandbox Code Playgroud)
将它们分成一个数组.最后,我使用代码:
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);
}
Run Code Online (Sandbox Code Playgroud)
要将一些段落或图像添加到richtextbox中,一切进展顺利,但当我向下滚动richtextbox时,其余段落消失.它整天困扰我,因为我无法找出richtextbox的错误.它只是Windows手机中的一个错误吗?有什么想法吗?
ScreenShot1:

ScreenShot2:

ps:html源代码是否包含一些非英文字符并不重要.当html源代码包含大量单词时会发生这种情况.这两个ScreenShot只显示了这个问题.
手机应用UIElement任何方向上任何不能超过2048像素的限制.这是为了避免与内存相关的性能问题并且必须绘制非常大的对象.这是为了保护您不会做出影响性能的事情,但也有其他原因.例如,手机是用于阅读大量文本的不良设备.对于密集的文本体,这尤其适用.因此,此大小限制会强制您考虑如何或应该在应用程序中显示大量文本.
但是有一些解决方案.您可以考虑使用以下内容:http://blogs.msdn.com/b/priozersk/archive/2010/09/08/creating-scrollable-textblock,
而不是使用单个Paragrpah或TextBlock大型"单元"文本.-用于-wp7.aspx