簡體   English   中英

如何在Metro Style Apps中傳遞框架導航中的多個參數?

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

我正在為Win8構建一個Metro Style App,它需要在幀導航上傳遞兩個文本塊值。 對於一個參數,它可以工作但是對於兩個參數它不起作用。 請幫忙! 我嘗試過如下:this.Frame.Navigate(typeof(SecondPage),textblock1.Text + textblock2.Text);

我沒有顯示任何錯誤,但它沒有工作。

創建一個包含2個屬性的新類,並將屬性設置為文本塊值。 然后在導航時傳遞此對象。

創建有效負載類:

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

然后填充有效負載類:

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

然后,當您調用Navigate時,傳遞您的有效負載實例,如下所示:

this.Frame.Navigate(typeof(SecondPage),payload);

我已經拿了這樣的字典對象。

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

在ViewDetails.xaml.cs頁面上,我檢索了這樣的數據,

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();
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM