0

I have a text which may contain some special characters like <b></b> or a link. I want the user to be able to click on the link and open it. TextBlock or RichTextBox seems doesn't show links in a proper way:

<RichTextBox >
  <Paragraph>
       click here: http://www.google.com
  </Paragraph>
</RichTextBox>

How can I show a text like that in a page?

Update: seems my question isn't clear. I ask a server for content and it returns back to me something like this:

 from <b><i><a href="http://www.google.com" rel=nofollow> lorem ipsom
 NPR:&#13;&#13; tapped in front of you probably know Bill Gates...

I want to show this in a WINDOWS PHONE page. TextBlock doesn't render it well. how can I show it human readable?

user2970840
  • 1,231
  • 2
  • 9
  • 13
  • Check this other SO question which, I think, has the answer you're looking for: http://stackoverflow.com/questions/531621/how-to-make-a-simple-hyperlink-in-xaml – Aage Nov 09 '13 at 22:36
  • or this one [Example using Hyperlink in WPF](http://stackoverflow.com/a/10238715/2145211) – Harrison Nov 09 '13 at 22:36
  • Oh guys. those answers aren't related to my question. I have a text which I have got it from a web page, it may have some links inside it or may have bold or other things.. I want to be able to show these contents. it is not about a hyperlink control or even doesn't relate to `WPF`! – user2970840 Nov 09 '13 at 22:40
  • Not sure if this would help but also you can look at the [`System.Windows.Documents.Hyperlink` Class](http://msdn.microsoft.com/en-us/library/system.windows.documents.hyperlink(v=vs.110).aspx) – Harrison Nov 09 '13 at 22:43
  • @user2970840. Maybe you should clarify your question. You tagged XAML aka WPF. It sounds like your question is _how do I display html in a WPF application?_? – Harrison Nov 09 '13 at 22:46
  • If that's the case how about [How to display the formatted Html in WPF control other than webbrowser control?](http://stackoverflow.com/a/13996695/2145211) – Harrison Nov 09 '13 at 22:49
  • @Harrison I have updated my question. there are some other guys at the corner of the world are writing apps for `Windows Phone` `Windows 8` etc. they use `XAML` as well! – user2970840 Nov 09 '13 at 22:51

1 Answers1

0

The way to solve your problem I see in using of WebBrowser control.

Then, accordingly to the article, you should go with Javascript to manage the links clicking etc (unless you want the links would be opened automatically with standard logic of Windows Phone):

Script is disabled in the WebBrowser control by default. Set the IsScriptEnabled property to true if you want to enable scripting in your control. You can then call scripts using the InvokeScript method. The ScriptNotify event occurs when JavaScript in the WebBrowser control passes a string to managed code.

That's a bit tricky way, but if you want to go any other way, you would have to implement your own parser of the code and build the sentence with labels and custom hyperlinks (as in provided above suggestions from comments).

Agat
  • 4,577
  • 2
  • 34
  • 62