在 WP7 应用程序中显示 Richtext

发布于 2024-12-08 22:27:09 字数 122 浏览 0 评论 0原文

我想在我的 WP7 应用程序中显示关于文本。但它包含链接、粗体文本和项目符号列表。有没有一种简单的方法可以将其显示为某种富文本或html?我不想使用带有文本块和超链接的堆栈面板来构建它......

I want to display an about text in my WP7 app. But it contains links, bold text and an bullet point list. Is there an easy way to display this as some kind of richtext or html? I don't want to build this using a stackpanel with textblocks and hyperlinks ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏见 2024-12-15 22:27:09

Windows Phone 的 Mango 版本将 Silverlight 版本从 3 提升到 4。作为其中的一部分,他们引入了 RichTextBox 控件,该控件可以满足您的需要。 '

一篇文章(诚然是旧的)是关于 首先看一下RichTextBox控件

The Mango release of Windows Phone bumped the Silverlight version from 3 to 4. As part of this they brought in the RichTextBox control that may do what you need. '

One article (admittedly old) about is First Look at RichTextBox Control.

心房敞 2024-12-15 22:27:09

如果要显示 HTML 页面或文件,则应使用 Web浏览器控件。它支持您期望从网络浏览器获得的所有基本功能; html 标记、样式、锚标记跳转到页面中的其他资源或位置。

要显示位于 Visual Studio 项目内的文件,您需要执行类似的操作。如果您需要更多信息,请告诉我。希望这有帮助。

阿尔。

===更新===

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

If you have an HTML page or file to display, you should use the WebBrowser control. It supports all the basic functionality you'd expect from a web browser; html markup, styling, anchor tags jumps to other resources or locations with in you page.

To display a file located inside a Visual Studio project, you'll need to do something like this. Let me know if you need additional information. Hope this helps.

Al.

=== updated ===

/// <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
            }
        }
    }
}

and then in your xaml

MyWebControl.NavigateToHtmlFile(pathToHtmlFile);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文