private Task <IHtmlBinding> Navigate(Uri uri, object viewModel, JavascriptBindingMode mode = JavascriptBindingMode.TwoWay) { if (uri == null) { throw ExceptionHelper.GetArgument($"ViewModel not registered: {viewModel.GetType()}"); } _Navigating = true; var oldvm = GetMainViewModel(Binding) as INavigable; if (_UseINavigable && (oldvm != null)) { oldvm.Navigation = null; } if (_CurrentWebControl != null) { _CurrentWebControl.HtmlWindow.Crashed -= Crashed; } var closetask = (_CurrentWebControl != null) ? _Window.CloseAsync() : TaskHelper.Ended(); _NextWebControl = _WebViewLifeCycleManager.Create(); _NextWebControl.HtmlWindow.ConsoleMessage += ConsoleMessage; var moderWindow = _NextWebControl.HtmlWindow as IModernWebBrowserWindow; var injectorFactory = GetInjectorFactory(uri); var engine = new HtmlViewEngine(_NextWebControl, injectorFactory, _webSessionLogger); var dataContext = new DataContextViewModel(viewModel); var initVm = HtmlBinding.GetBindingBuilder(engine, dataContext, mode); if (moderWindow != null) { var debugContext = _WebViewLifeCycleManager.DebugContext; EventHandler <BeforeJavascriptExcecutionArgs> before = null; before = (o, e) => { moderWindow.BeforeJavascriptExecuted -= before; e.JavascriptExecutor(_JavascriptFrameworkManager.GetMainScript(debugContext)); }; moderWindow.BeforeJavascriptExecuted += before; } var tcs = new TaskCompletionSource <IHtmlBinding>(); EventHandler <LoadEndEventArgs> sourceupdate = null; sourceupdate = async(o, e) => { _NextWebControl.HtmlWindow.LoadEnd -= sourceupdate; var builder = await initVm; await builder.CreateBinding(_WebViewLifeCycleManager.DebugContext).WaitWith(closetask, t => Switch(t, dataContext.Window, tcs)).ConfigureAwait(false); }; Url = uri; _NextWebControl.HtmlWindow.LoadEnd += sourceupdate; _NextWebControl.HtmlWindow.NavigateTo(uri); return(tcs.Task); }