Abbas Galiyakotwala
Abbas Galiyakotwala

Reputation: 3019

Windows Phone 8.1 phone parameter data on backward navigation

I am creating a Windows Phone 8.1 App.

There are some screens on my app. On the first screen, I am navigate my screen to second screen with a parameter data. now i want to navigate to first screen from second screen with different parameter data.

Using Frame.Navigate(typeof(frame1),parameter); I can pass data from first screen to second screen (forward navigation)

Frame.Navigate(typeof(frame1), "data");

but how can I pass data from second screen to first screen (backward navigation) ?

Upvotes: 1

Views: 101

Answers (2)

Michael Mairegger
Michael Mairegger

Reputation: 7301

There is no easy solution. Using the Frame.GoBack method you cannot pass a parameter. Furthermore if you use NavigationHelper.GoBack you cannot pass a parameter neither. This is by desing. If you go back, you will open the view that was previous open. That is the definition of going back. You want to "restore" a previous state.

But there would be a possible solution, when you store your new data into a variable that you can access from frame1.

Can you state why you would use a different data for backwards navigation?

Another, better possibility is to use a ContentDialog. There you can add your desired ViewModel to the DataContext prior opening. After that the ContentDialog is closed you can validate the data passed to it.

ContentDialog cd = new MyContentDialog();

if (parameter != null)
{
    cd.DataContext = // set context here;
}
await cd.ShowAsync();
//now lets validate or process the necessary data.

Upvotes: 1

fillobotto
fillobotto

Reputation: 3775

The only solution I can think of is to declare a global variable in App.xaml.cs so that you can access it from Frame2 and set a value, then you get the value from Frame1.

public static Object navigationData
{
      get;
      set;
 }

And from everywhere you access it using

var data = App.navigationData;

Upvotes: 1

Related Questions