Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing Html in WinRT with RichTextBlock or other component

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, ...).

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

like image 282
Libor Zapletal Avatar asked Oct 26 '12 13:10

Libor Zapletal


2 Answers

I finally got fed up with the lack of WinRT-supported Html to Xaml conversion and wrote my own. For kicks, I put it on codeplex. For even further kicks, and to experiment with NuGet, I published it there, too...

Obviously, this isn't the end-all of Html to Xaml conversion, but it's a start...

like image 161
Jacob Proffitt Avatar answered Oct 06 '22 02:10

Jacob Proffitt


You have 2 ways

  1. build or get your own html to xaml parser to use the contents as RichTextBox Source
  2. Use WebView to display html content

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

  • javascript support
  • css support
  • bad formed (real world) html support
  • etc

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

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

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

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

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.

like image 25
3 revs Avatar answered Oct 06 '22 03:10

3 revs