无法为这个问题找到任何答案,所以想出了我自己的解决方法。首先,我检查要显示的内容的长度,然后如果超过 4000 个字符长度,那么我将其分为两部分。然后还添加了一个带有更多按钮的应用程序栏,以便用户可以单击该按钮并查看剩余的文本。这是代码
{
if (commentry.Length > 4000 && commentry.IndexOf("<p>", commentry.Length / 2) > 0)
{
//Change the xaml to contain a panaroma , and if then on the second item create web browser control with the second half of the commentry.
commentry1 = commentry.Remove(commentry.IndexOf("<p>", commentry.Length / 2), commentry.Length - commentry.IndexOf("<p>", commentry.Length / 2));
commentry2 = commentry.Remove(0, commentry.IndexOf("<p>", commentry.Length / 2));
appBarMoreButton = new ApplicationBarIconButton(new Uri("/Images/quote.back.png", UriKind.Relative));
appBarMoreButton.Text = "more";
appBarMoreButton.Click += new EventHandler(loadMoreContent);
appBarPreviousButton = new ApplicationBarIconButton(new Uri("/Images/quote.back.png", UriKind.Relative));
appBarPreviousButton.Text = "Previous";
appBarPreviousButton.Click += new EventHandler(loadFirstPart);
}
var htmlScript = "<script>function getDocHeight() { " +
"return document.getElementById('pageWrapper').offsetHeight;" +
"}" +
"function SendDataToPhoneApp() {" +
"window.external.Notify('' + getDocHeight());" +
"}</script>";
if (commentry1 == null && commentry2 == null)
{
var htmlConcat = string.Format("<html><meta name=\"viewport\" content=\"width=device-width,user-scalable=yes,height=device-height\" /><head>{0}</head>" +
"<body style=\"margin:5px;padding:0px;background-color:{3};\" " +
"onLoad=\"SendDataToPhoneApp()\">" +
"<div id=\"pageWrapper\" style=\"width:100%;color:{2}; background-color:{3}\"> " +
"{1}</div></body><footer></footer></html>",
htmlScript,
commentry, fontColor, backGroundColor);
discusswebBrowser.NavigateToString(htmlConcat);
}
else
{
var htmlConcat = string.Format("<html><meta name=\"viewport\" content=\"width=device-width,user-scalable=yes,height=device-height\" /><head>{0}</head>" +
"<body style=\"margin:5px;padding:0px;background-color:{3};\" " +
"onLoad=\"SendDataToPhoneApp()\">" +
"<div id=\"pageWrapper\" style=\"width:100%;color:{2}; background-color:{3}\"> " +
"{1}</div></body><footer></footer></html>",
htmlScript,
commentry1, fontColor, backGroundColor);
discusswebBrowser.NavigateToString(htmlConcat);
ApplicationBar = new ApplicationBar();
ApplicationBar.IsVisible = true;
ApplicationBar.Mode = ApplicationBarMode.Minimized;
ApplicationBar.IsMenuEnabled = false;
ApplicationBar.Buttons.Add(appBarMoreButton);
}
discusswebBrowser.ScriptNotify +=
new EventHandler<NotifyEventArgs>(wb1_ScriptNotify);
}
为更多按钮的事件处理程序创建一个函数,该函数将加载剩余文本以及应用程序栏中的按钮以移回第一部分。
private void loadMoreContent(object sender, EventArgs e)
{
if (commentry2 != null)
{
var htmlScript = "<script>function getDocHeight() { " +
"return document.getElementById('pageWrapper').offsetHeight;" +
"}" +
"function SendDataToPhoneApp() {" +
"window.external.Notify('' + getDocHeight());" +
"}</script>";
var htmlConcat = string.Format("<html><meta name=\"viewport\" content=\"width=device-width,user-scalable=yes,height=device-height\" /><head>{0}</head>" +
"<body style=\"margin:5px;padding:0px;background-color:{3};\" " +
"onLoad=\"SendDataToPhoneApp()\">" +
"<div id=\"pageWrapper\" style=\"width:100%;color:{2}; background-color:{3}\"> " +
"{1}</div></body><footer></footer></html>",
htmlScript,
commentry2, fontColor, backGroundColor);
discusswebBrowser.NavigateToString(htmlConcat);
this.ApplicationBar.Buttons.RemoveAt(0);
this.ApplicationBar.Buttons.Add(appBarPreviousButton);
}
}