在 WinRT 中使用 RichTextBlock 或其他组件显示 Html [英] Showing Html in WinRT with RichTextBlock or other component

查看:29
本文介绍了在 WinRT 中使用 RichTextBlock 或其他组件显示 Html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一些组件在字符串中显示 html.现在我正在使用 RichTextBlock 并且我尝试了一些将 html 转换为 xaml 或 rtf 的扩展,但我没有发现任何可以使用 WinRT.我知道我可以使用 WebView,但它不是那么漂亮.我只想对 ItemDetailPage (使用 RichTextBlock 的地方)做些小改动,以向用户展示基本的 html(粗体、斜体、链接、图像……).

I want to show html in string with some component. Now I am using RichTextBlock and I tried few extensions for converting html to xaml or rtf but I didn´t found any working with WinRT. I know I can use WebView but it isn´t so pretty. I just want to do little change to ItemDetailPage (where is used RichTextBlock) to show users elementary html (bold, italics, links, images, ...).

是否有一些组件或某种方式可以做到这一点(不是 webview)?还是有工作转换器?

Is there some component or some way how to do this (not webview)? Or is there working convertor?

推荐答案

你有两种方法

  1. 构建或获取您自己的 html 到 xaml 解析器以将内容用作 RichTextBox 源
  2. 使用 WebView 显示 html 内容

我推荐 WebView,因为这个组件有很多功能很难作为解析器实现

I recommend WebView because this componente have a lot of features that is very difficult to implement as a parser

  • javascript 支持
  • CSS 支持
  • 不良格式(现实世界)html 支持

因此,在 WebView 控件中,您可以使用 WebView.NavigateToString 方法来显示存储在字符串中的 html 内容.

So, in a WebView control you can use WebView.NavigateToString method to display html contents stored in a string.

您甚至可以修改字符串以更改样式、添加脚本等,因为您需要自定义 web 视图的外观.

Yo can, even, modify string to changes styles, add scripts, etc as you need to custom webview look and feel.

NavigateToString 不支持绑定,但我写了一篇文章(西班牙语)教如何使用附加属性:http://blogs.msdn.com/b/juank/archive/2012/10/29/tutorial-crear-app-lector-rss-winrt-parte-7.aspx

NavigateToString has no support for binding but I wrote an article (spanish) teaching how to doing using attached properties: http://blogs.msdn.com/b/juank/archive/2012/10/29/tutorial-crear-app-lector-rss-winrt-parte-7.aspx

使用此代码(plex)进行解析,如果它不完全适合您可以更改您自己的代码.;) http://html2xaml.codeplex.com/

Use this code(plex) to parsing, if it not fit exactly you can change te code for your own. ;) http://html2xaml.codeplex.com/

否则您将自己创建 ode,如果您想在列文本中分页(横向阅读),您必须使用 RichTextBlock,使用 RichTextColumns hepler 类(当您从模板启动应用程序时包含在 Common/文件夹中)和尝试将 HTML 解析为 XAML.

Other wise you would create the ode yourself, if you want break pages in column text (to horizontal reading) you must use RichTextBlock, use RichTextColumns hepler class ( included in Common/ folder when you start your app from a template) and try to parse HTML to XAML.

这篇关于在 WinRT 中使用 RichTextBlock 或其他组件显示 Html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆