NavigationFailed event. That??™s
because the attempt to navigate to a website could fail if the computer isn??™t online, the site
isn??™t available, or the web content can??™t be reached. In this case, the network stack returns an
error like ???404: File Not Found,??? which becomes aWebException.
In order to handle this exception gracefully and prevent your application from shutting
down unexpectedly, you need to neutralize it with an event handler like this:
Private Sub Application_NavigationFailed(ByVal sender As Object, _
ByVal e As System.Windows.Navigation.NavigationFailedEventArgs) _
Handles Me.NavigationFailed
If TypeOf e.Exception Is System.Net.WebException Then
MessageBox.Show("Website " & e.Uri.ToString() & " cannot be reached.")
' Neutralize the error so the application continues running.
e.Handled = True
End If
End Sub
NavigationFailed is just one of several navigation events that are defined in the
Application class. You??™ll get the full list later in this chapter, in Table 9-2.
CHAPTER 9 n PAGES AND NAVIGATION 255
nNote Once you lead users to a web page, they??™ll be able to click its links to travel to other web pages,
leaving your content far behind. In fact, they??™ll return to your WPF page only if they use the navigation history
to go back or if you??™re showing the page in a custom window (as discussed in the next section) and that
window includes a control that navigates back to your content.
Pages:
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473