Intersoft ClientUI 8 > ClientUI Fundamentals > Navigation Overview > Navigation How-to Topics > How-to: Navigate to a Page with Extra Data |
This example shows how to navigate to a UXPage and pass along an extra data during the navigation process.
In Silverlight applications, you typically pass additional data to pages using query string through user-friendly URIs that implemented in UriMapper class in the UXFrame. For more information about the user-friendly URIs concept, see Navigation Overview.
However, since the query string nature is generally in the form of string type, you may find it difficult to pass extra data that use complex type such as a custom object. UXFrame provides built-in capability to navigate to a page with specified extra data which allows you to pass a custom object with complex type and then retrieve the object in the navigation events.
UXFrame implements Navigate overload that allows you to pass an extra data during navigation. The following example shows how to navigate to a user-friendly error page and pass along the ApplicationUnhandledExceptionEventArgs object provided in the event data of the UnhandledException event that raised by the Application class.
The Navigate method overload with extra data parameter is compatible between Silverlight and WPF platform. |
C# |
Copy Code
|
---|---|
public App() { this.UnhandledException += this.Application_UnhandledException; InitializeComponent(); } private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { if (!System.Diagnostics.Debugger.IsAttached) { e.Handled = true; // Displays a user-friendly error page to the primary navigation (UXFrame) of the application Deployment.Current.Dispatcher.BeginInvoke(delegate { DisplayErrorToNavigationFrame(e); }); } } private void DisplayErrorToNavigationFrame(ApplicationUnhandledExceptionEventArgs e) { // Get the primary UXFrame that existed in the RootVisual UXFrame frame = UXFrame.GetPrimaryNavigator(this.RootVisual); if (frame != null) { // Navigate to the error page and pass along the event data frame.Navigate(new Uri("/Error", UriKind.Relative), e); } } ... |
In the code behind of the Error page, you can retrieve the passed extra data from the ExtraData property available in the event data of the OnNavigatedTo protected method, such as shown in the following example.
C# |
Copy Code
|
---|---|
public partial class ErrorPage : UXPage { public ErrorPage() { InitializeComponent(); } // Executes when the user navigates to this page. protected override void OnNavigatedTo(NavigationEventArgs e) { if (e.ExtraData == null) { // user inadvertently landed to the error page, redirect to the home page this.GetNavigator().Navigate(new Uri("/Home", UriKind.Relative)); return; } ApplicationUnhandledExceptionEventArgs errorArgs = e.ExtraData as ApplicationUnhandledExceptionEventArgs; errorDetails.Text = errorArgs.ExceptionObject.Message + "\n" + errorArgs.ExceptionObject.StackTrace; } } |