Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Last active November 2, 2018 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannagel/37dc38f73d0d175ae702c237e763776e to your computer and use it in GitHub Desktop.
Save christiannagel/37dc38f73d0d175ae702c237e763776e to your computer and use it in GitHub Desktop.
Navigation with the WebView in WPF
private void WebView_Loaded(object sender, RoutedEventArgs e)
{
if (sender is WebView webView)
{
webView.NavigationCompleted += (sender1, e1) => CommandManager.InvalidateRequerySuggested();
}
}
private void OnGoToPage(object sender, ExecutedRoutedEventArgs e)
{
try
{
webView1.Navigate(textUrl.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
private void OnBrowseBack(object sender, ExecutedRoutedEventArgs e) =>
webView1.GoBack();
private void OnBrowseForward(object sender, ExecutedRoutedEventArgs e) =>
webView1.GoForward();
private void CanBrowseForward(object sender, CanExecuteRoutedEventArgs e) =>
e.CanExecute = webView1?.CanGoForward ?? false;
private void CanBrowseBack(object sender, CanExecuteRoutedEventArgs e) =>
e.CanExecute = webView1?.CanGoBack ?? false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment