[英]passing information between pages in windows phone 8
我需要在Windows Phone 8的三個頁面之間傳遞一個簡單的texbox。我一直在搜索,但是找不到,我嘗試過這個,' https: //msdn.microsoft.com/en-us/library/windows/apps /xaml/hh771188.aspx '我在此方法中遇到問題:
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
string name = e.NavigationParameter as string;
if (!string.IsNullOrWhiteSpace(name))
{
tb1.Text = "Hello, " + name;
}
else
{
tb1.Text = "Name is required. Go back and enter a name.";
}
}
我找不到LoadStateEventArgs e,缺少using指令或程序集引用。
如果我正確理解了您的問題,則希望將該值存儲在3個不同頁面的文本框中。 對 ?
檢查並讓我知道
// let's assume that you have a simple class:
public class PassedData
{
public string Name { get; set; } //for textBox1
public string Name1 { get; set; } //for textBox2
public string Name3 { get; set; } //for textBox3
public string Name4 { get; set; } //for textBox4
public string Name5 { get; set; } //for textBox5
public int Value { get; set; }
}
//create object of the class like this and asign values to the properties
PassedData abc=new PassedData();
abc.Name=TextBox1.Text;
abc.Name2=TextBox2.Text;
abc.Name3=TextBox3.Text;
abc.Value=TextBox4.Text.ToString();
// then you navigate like this:
Frame.Navigate(typeof(Page2), abc);
// and in target Page you retrive the information:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
PassedData data = e.Parameter as PassedData;
}
我不會過多地關注傳遞的數據,而是關注作為應用程序骨干的數據模型。 應該有一個數據模型類,其中包含要存儲的文本內容。 此類的實例應“存活”任何頁面,因此,如果有一個頁面寫入該屬性,則可以有另一個頁面顯示此字段的值。 您還應該考慮為每個頁面創建一個視圖模型,用作在模型和頁面之間傳遞屬性值的粘合代碼,如果您具有類型轉換,數據驗證,必填字段等也可以提供幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.