Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.