How to access NavigateToString property of a WebVi

2019-02-27 04:15发布

I've got a ListView which contains, among other things, a WebView. When a ListViewItem on this list is selected, I'd like to bind HTML to the WebView via the NavigateToString method.

The WebView needs be in the bound list (as it's tied to a list of items), and must use NavigateToString (as the HTML content is coming from code, and is not on the web)

Is there anyway to do this? If so, what's the best way?

1条回答
Juvenile、少年°
2楼-- · 2019-02-27 05:01

Of course, you can add an attached behavior using either an attached dependency property or a Behavior that you could bind a string to that will navigate to that string when the value changes (e.g. when it is first assigned).

The other problem could be though with how it performs. I would think of the WebView control as a browser window, so if you have a hundred items in your ListView you might not want to create a hundred IE windows for all of them. Even assuming you use the default VirtualizingStackPanel as the ItemsPanel of your ListView - this sounds like a source of many issues. I haven't tried that, so I might be wrong, but I would rather try parsing the html and formatting it for use in regular TextBlocks. For very basic html you could use the LinkedHtmlFragment extension of the WinRT XAML Toolkit with a RichTextBlock if all you have is plain text and links. For something more fancy you might need to do some coding yourself or use something like the HTML Agility Pack (though I am not sure if it supports WinRT yet).

查看更多
登录 后发表回答