Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass more than one parameter on frame navigation in Metro Style Apps?

Tags:

c#

windows-8

I am building a Metro Style App for Win8 which requires to pass two textblock values on frame navigation. For one parameter, it works but for two parameters its not working. Please help! I have tried like the following: this.Frame.Navigate(typeof(SecondPage),textblock1.Text + textblock2.Text);

I doesn't show any error but its not working.

like image 624
Shan Avatar asked May 03 '12 06:05

Shan


2 Answers

Create a new class with 2 properties and set the properties to the textblock values. Then you pass this object when you navigate.

Create the payload class:

public class Payload
{
 public string text1 { get;set;}
 public string text2 { get;set;}
}

Then populate the payload class:

Payload payload = new Payload();
payload.text1 = textblock1.Text;
payload.text2 = textblock2.Text;

Then when you call Navigate pass your instance of payload like this:

this.Frame.Navigate(typeof(SecondPage),payload);
like image 75
Allan Muller Avatar answered Nov 03 '22 01:11

Allan Muller


I have taken a dictionary object like this.

Dictionary<string, string> newDictionary = new Dictionary<string, string>();
newDictionary.Add("time", itemObj.repTime);
newDictionary.Add("message", itemObj.repMessage);
Frame.Navigate(typeof(ViewDetails),newDictionary);

On ViewDetails.xaml.cs page I had retrieved the data like this,

protected override void OnNavigatedTo(NavigationEventArgs e)
    {
         Dictionary<string, string> myDictionary = new Dictionary<string, string>();
         myDictionary = e.Parameter as Dictionary<string, string>;
         timeTB.Text = myDictionary["time"].ToString();
         messageTB.Text = myDictionary["message"].ToString();
    }
like image 1
Arjun K R Avatar answered Nov 03 '22 01:11

Arjun K R