Is there way to use WebView without actual page?
I tried to instantiate webview via new WebView() and then call Navigate to url but navigation completed handler that I register for is not called.
Is there way to use WebView without actual page?
I tried to instantiate webview via new WebView() and then call Navigate to url but navigation completed handler that I register for is not called.
I tried to instantiate webview via new WebView() and then call Navigate to url but navigation completed handler that I register for is not called.
We need to add the WebView
control into to a xaml container(Grid
, StackPanel
etc), then the WebView.NavigationCompleted event will be called when the WebView
has finished loading the current content or if navigation has failed.
For example:
XAML:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" x:Name="rootGrid">
</Grid>
Code Behind:
public MainPage()
{
this.InitializeComponent();
WebView wb = new WebView();
wb.Source = new Uri("http://www.microsoft.com");
wb.NavigationCompleted += Wb_NavigationCompleted;
rootGrid.Children.Add(wb);
}
private void Wb_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
throw new NotImplementedException();
}
If you don't want to show WebView page in your UI, just set Visibility
property to Collapsed
wb.Visibility = Visibility.Collapsed;
------Update 07/28/2016-------
If you just need to load html page from code behind, the WebView
control is not the right choice, there are two solutions:
Using HttpClient
class to request webpage
Check the official sample
Using third-party library, for example, Html Agility Pack, please see Sunteen's answer in this question: HtmlAgility:no contents appeared (C#,UWP)