我知道我可以在頁面之間傳遞值與URI,例如:如何在頁面之間傳遞值? (Windows手機)
NavigationService.Navigate(
new Uri("/DestinationPage.xaml?parameter1=v1", UriKind.Relative)
);
是否有任何其他的方法,我怎麼能在頁面之間傳遞值?
我知道我可以在頁面之間傳遞值與URI,例如:如何在頁面之間傳遞值? (Windows手機)
NavigationService.Navigate(
new Uri("/DestinationPage.xaml?parameter1=v1", UriKind.Relative)
);
是否有任何其他的方法,我怎麼能在頁面之間傳遞值?
您可以像使用
NavigationService.Navigate(new Uri("/MainPage.xaml?value=Hello%20World", UriKind.Relative);
和值可以傳遞給爲
string value = this.NavigationContext.QueryString["value"];
除了在頁面URI字符串傳遞,並與NavigationContext檢索它們的查詢字符串值,有ISN沒有任何開箱即用的選擇!
但是,您可以隨時在App類中聲明所有頁面都可用的公共屬性!
你可以做一個單身人士;)。 下面是一個例子:
public class MySingleton
{
private static MySingleton _mInstance;
public static MySingleton Instance
{
get { return _mInstance ?? (_mInstance = new MySingleton()); }
}
/// <summary>
/// You can send values through this string.
/// </summary>
public string SomeString { get; set; }
}
編輯:要將值分配給它,你可以做這樣的事情:
MySingleton.Instance.SomeString = "Text";
你可以通過使用IsolatedStorageSetting值,你已經使用isolatedStorage時要小心,您必須手動清除它,否則它將不會被清除,除非您這樣做或卸載應用程序/關閉仿真器,IsolatedStorage Documentation
<Button Content="Next page" Grid.Column="1" Height="23" Tag="/NextPage.xaml" HorizontalAlignment="Right" Margin="0,6,12,0" Name="btnViewQuestion" VerticalAlignment="Top" Width="100" />