开发者

WP7 - Bind an ItemsControl item to a VM property containing HTML string

I'm displaying a list of data in an ItemsControl. I'm binding my ItemsControl to an ObservableCollection of a ViewModel representing each item. In the item's ViewModel, there is a property containing HTML as a string, which I'd like to display as rich text as in a WebBrowser control.

I'm relatively new to WP7, so I'm looking up how to handle this. What I've found so far is that I need a WebBrowser control and call NavigateToString on it. My problem is that this needs to b开发者_开发百科e displaying as a list item which I have defined in a DataTemplate. Is there a way to handle this with bindings? Is there another way besides WebBrowser to display strings with HTML formatting?


Another way to display strings with HTML formatting is to parse the strings with your own code transforming it to a Xaml string that has the approximate formatting.

How close you can get the generated Xaml to the HTMLs intended rendering will vary on the effort put in. For example it should be fairly easy to replace <b>..</b> with <run FontWeight="Bold">..</run>. Much depends on how sophisticated the input HTML strings are.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜