wp7 - webbrowser control

Feb 2, 2011 at 6:06 PM

I'm trying to display HTML in the webbrowser control and I'm not sure the best way to do it with CM.  I have a view which essentially is just a holder for the webbrowser control so they can see some web content while in my app.  When tapping an item on a previous page I navigate to the page with the browser control on it.  By default, you have to call a method on the control to get it to browse to a page though there are some extensions that supposedly make it possibly to bind to a ViewModel property that returns HTML.  If that works I guess I could have the ViewModel query to get the HTML and then get browser control binding to work.

Are there any examples of working with the browser control?  I've not found any.  I know about the task launcher to open IE but I'd rather give the option of viewing the content first and then launching IE if they choose.

Thanks

Feb 3, 2011 at 7:49 AM

If you don't have to intercept the click of hyperlink or the HTML loading from the VM side, then you might consider hooking the webbrowser event and calling the navigation method directly in the view side.
I don't see anything wrong in using the code-behind if you're not going to alter a "classic" browsing process. 

If you really want, you can provide a bindable property to the browser control or to the view holding it, and proceed with usual MVVM binding tecniques.
But, again, my advice is to avoid this approach if the VM has the only responsibility to configure the initial URL.

In order to let the VM communicate to the browser the starting URL, you might consider using an MVP approach: retrieve the instance of the view through
IViewAware.GetView method (your VM should implement IViewAware or inherit from Screen), then access the browser by name.
Another (cleaner) option is to use a custom IResult; the result instance is able to access the view from the context passed to  the IResult.Execute method.

 

Feb 3, 2011 at 2:50 PM

@surfermikel

A simplistic example, if you don't mind bringing view into viewmodel:

class MyViewModel {
...
public strin HtmlContent {get;set}
protected override void OnViewLoaded(object view)
{
	base.OnViewLoaded(view);

	var itemView = view as MyViewView;
	if (itemView == null)
		throw new ArgumentException();

	var webBrowser = itemView.browser;
	webBrowser.NavigateToString(HtmlContent);
}

 
Feb 3, 2011 at 5:35 PM

Thanks!  I will try these ideas out.

Mar 18, 2014 at 12:39 AM
Thank you !!