-
-
Save christiannagel/37dc38f73d0d175ae702c237e763776e to your computer and use it in GitHub Desktop.
Navigation with the WebView in WPF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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