I have a WPF application that consumes a SharePoint list using Client Object Model.

The customer wants to be able to fill in one of the fields with Rich Text. This includes formatting like bold/color/font type/etc. It also includes hyperlinks.

In information I get from SharePoint is stored in a string, and looks something like this:

<div class=\"ExternalClass82C42B1E597D49188F88ECA8C4EEB083\"><p>Ticker Item 3 Body<span style=\"color:#000000\"></span>y<</p></div>

When I use the advise I found here: Can I bind HTML to a WPF Web Browser Control?

It comes out looking like this:

Ticker Item 3 Body​

What's up with the little "​" at the end? Is there a correct way of showing Rich Text in my WPF app that includes clickable hyper links and formatting?

Thanks in advance.

有帮助吗?

解决方案

For anyone coming here and looking for a solution, the answer is twofold.

1) The wrong question is being asked. Using a Web Browser Control is not the best way to do this. You can't force links to open up in IE (at least, not easily), and the window will behave like a web browser. Pressing F5 will refresh the window, which will empty it, since there is no address in the browser.

In any event, the issue was that WPF wasn't using the correct character set. Adding this to your html will fix the browser issue:

html = String.Format("<html><META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; CHARSET=utf-8\"><body>{0}</body></html>", html);

2) What you actually want to do is use a FlowDocumentScrollViewer. Instructions on how to do that are here: How can I get a FlowDocument Hyperlink to launch browser and go to URL in a WPF app?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top