Freigeben über


Frame.NavigationFailed Event

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Occurs when an error is encountered while navigating to the requested content.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Navigation (in System.Windows.Controls.Navigation.dll)

Syntax

'Declaration
Public Event NavigationFailed As NavigationFailedEventHandler
public event NavigationFailedEventHandler NavigationFailed
<sdk:Frame NavigationFailed="eventhandler"/>

Examples

The following example shows the XAML for a frame that includes an event handler for the NavigationFailed event.

<sdk:Frame 
       x:Name="ContentFrame" 
       Style="{StaticResource ContentFrameStyle}" 
       Source="/Home" 
       Navigated="ContentFrame_Navigated" 
       NavigationFailed="ContentFrame_NavigationFailed">
    <sdk:Frame.UriMapper>
        <sdk:UriMapper>
            <sdk:UriMapping 
                Uri="/ProductDetail/{productid}" 
                MappedUri="/Views/ProductDetail.xaml?ProductId={productid}"/>
            <sdk:UriMapping 
                Uri="/Reports/{type}/{selection}" 
                MappedUri="/Views/ReportsPage.xaml?type={type}&amp;selection={selection}"/>
            <sdk:UriMapping 
                Uri="/{pageName}" 
                MappedUri="/Views/{pageName}.xaml"/>
        </sdk:UriMapper>
    </sdk:Frame.UriMapper>
</sdk:Frame>

The following example shows a handler for the NavigationFailed event. When navigation to a page within the frame fails, a child window is displayed that contains an error message and the URI of the requested page. The code for the child window named ErrorWindow is not shown in this example, but must be included in the application for the example to work. The Handled property is set to true to indicate that the event has been handled and an exception should not be thrown.

Private Sub ContentFrame_NavigationFailed(ByVal sender As Object, _
         ByVal e As NavigationFailedEventArgs) Handles ContentFrame.NavigationFailed
    e.Handled = True
    Dim errorWindow As ChildWindow = New ErrorWindow(e.Uri)
    errorWindow.Show()
End Sub
private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
    e.Handled = true;
    ChildWindow errorWin = new ErrorWindow(e.Uri);
    errorWin.Show();
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.