Over a million developers have joined DZone.

Another Way of Passing Values Between Windows Phone 7 Pages

DZone's Guide to

Another Way of Passing Values Between Windows Phone 7 Pages

· Mobile Zone ·
Free Resource

Another appropriate way for passing data from one page to another during the navigation is in setting up destination page properties (or variables) within OnNavigatedFrom method of source page.

passing data or parameters from one page to another using onnavigatedfrom method and destination page instance by eugenedotnet

OnNavigatedFrom method is called just before a page is no longer the active page in a frame. For example this method is called if you invoke NavigationService.Navigate method from a source page. Due to the fact that OnNavigatedFrom method accepts NavigationEventArgs as input parameter you have access to the destination page stored in Content property.


I have created two pages: Page1.xaml and Page2.xaml. Inside Page2 I have added a string property named Parameter. Inside Page1 (codebehind) I have overridden method OnNavigatedFrom for setting up Page2′s Parameter property.

protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
    Page2 page2Instance = e.Content as Page2;
    if (page2Instance != null)
        page2Instance.Parameter = "value";


Probably one of advantages is that you don’t have to store values in static context, but simply pass them from one page to another. That approach is great for a wizard when you have several pages in a row and you need to store only the final result after wizard is completed.


This approach cannot be applied to applications that can lose sensitive information during the suspend mode (Tombstoning), because when system restores your application from suspend mode there is no way to call OnNavigatedFrom method to set destination page properties.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}