我想在我的WP7应用程序中显示一个关于文本。但是它包含链接、粗体文本和一个项目符号列表。有没有一种简单的方法将其显示为某种富文本或HTML?我不想使用堆栈面板和文本块与超链接来构建此内容...
我想在我的WP7应用程序中显示一个关于文本。但是它包含链接、粗体文本和一个项目符号列表。有没有一种简单的方法将其显示为某种富文本或HTML?我不想使用堆栈面板和文本块与超链接来构建此内容...
/// <summary>
/// Contains extension methods for the WebBrowser control.
/// </summary>
public static class WebBrowserExtensions {
private static void SaveFileToIsoStore(String fileName) {
//These files must match what is included in the application package,
//or BinaryStream.Dispose below will throw an exception.
using(IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) {
if (false == isoStore.FileExists(fileName)) {
StreamResourceInfo sr = Application.GetResourceStream(new Uri(fileName, UriKind.Relative));
using (BinaryReader br = new BinaryReader(sr.Stream)) {
byte[] data = br.ReadBytes((int)sr.Stream.Length);
SaveToIsoStore(fileName, data);
}
}
}
}
private static void SaveToIsoStore(string fileName, byte[] data) {
string strBaseDir = string.Empty;
string delimStr = "/\\";
char[] delimiter = delimStr.ToCharArray();
string[] dirsPath = fileName.Split(delimiter);
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) {
//Recreate the directory structure
for (int i = 0; i < dirsPath.Length - 1; i++) {
strBaseDir = System.IO.Path.Combine(strBaseDir, dirsPath[i]);
isoStore.CreateDirectory(strBaseDir);
}
//Remove existing file
if (isoStore.FileExists(fileName)) {
isoStore.DeleteFile(fileName);
}
//Write the file
using (BinaryWriter bw = new BinaryWriter(isoStore.CreateFile(fileName))) {
bw.Write(data);
bw.Close();
}
}
}
public static void NavigateToHtmlFile(this WebBrowser webBrowser, String fileName) {
SaveFileToIsoStore(fileName);
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) {
if (isoStore.FileExists(fileName)) {
webBrowser.Navigate(new Uri(fileName, UriKind.Relative));
} else {
//something bad has happened here
}
}
}
}
然后在你的XAML中
MyWebControl.NavigateToHtmlFile(pathToHtmlFile);
Windows Phone的Mango版本将Silverlight版本从3升级到4。作为其中的一部分,他们引入了RichTextBox控件,该控件可能会满足您的需求。
有一篇关于此控件的文章(尽管有些陈旧),链接如下:First Look at RichTextBox Control。