我知道我可以在页面之间传递值与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" />