在Windows Phone 8应用程序的表单之间交换数据
本文关键字:表单 之间 交换 数据 应用程序 Windows Phone | 更新日期: 2023-09-27 17:49:46
我使用以下代码在应用程序中的两个表单之间交换数据
从form1发送数据,如下所示
NavigationService.Navigate(new Uri(string.Format("/Form2.xaml?myparameter1={0}&myparameter2={1}", "text1", "text2"), UriKind.Relative));
在form2中接收数据,如下图
string receivedtext1 = null;
string receivedtext2 = null;
NavigationContext.QueryString.TryGetValue("myparameter1", out receivedtext1);
NavigationContext.QueryString.TryGetValue("myparameter2", out receivedtext1);
这是为我工作的字符串。
现在我的问题是,我们可以在两种形式之间以类似的方式交换字节[]作为字符串交换吗?
您可以使用PhoneApplicationservice在windows phone应用程序的页面之间传递数据。下面是PhoneApplicationService如何工作的一个简短示例,可能会对您有所帮助。
//Before navigation
PhoneApplicationService.Current.State["Data"] = your byte array;
NavigationService.Navigate(new Uri(string.Format("/Form2.xaml", UriKind.Relative));
//第二页
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var data =(Cast as byte array)PhoneApplicationService.Current.State["Data"]
PhoneApplicationService.Current.State.Remove("Data");
}