Windows phone 8 如何在xaml页面之间传递longlistselector数据
我尝试在xaml页面之间传递longlistselector数据。但它不起作用 如何使用查询字符串或任何其他可能的解决方案传递数据。请帮帮我 我尝试了以下代码:Windows phone 8 如何在xaml页面之间传递longlistselector数据,windows-phone-8,Windows Phone 8,我尝试在xaml页面之间传递longlistselector数据。但它不起作用 如何使用查询字符串或任何其他可能的解决方案传递数据。请帮帮我 我尝试了以下代码: public class PaymentItem { public string Home { get; set; } public string FirstName { get; set; } public string LastName { get; set; }
public class PaymentItem
{
public string Home { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public string Code { get; set; }
public string City { get; set; }
}
public class PaymentList : ObservableCollection<PaymentItem>
{
public PaymentList()
{
Add(new PaymentItem { Home = "Home", FirstName = "Kevin", LastName = "Peter", Address = "paris", Code = "23343", City = "France" });
}
}
private void imgEditdAddress_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
PaymentItem dataItem = ((FrameworkElement)sender).DataContext as PaymentItem;
QueryString不能与用户定义的对象一起使用,因为它只存储单个变量 可以在IsolatedStorage应用程序设置中存储用户定义的对象 在执行导航之前保存对象
IsolatedStorageSettings.ApplicationSettings["State"] = dataItem;
IsolatedStorageSettings.ApplicationSettings.Save();
在导航到处理程序的第二页,只需将对象取回即可
if (IsolatedStorageSettings.ApplicationSettings.Contains("State") == true)
{
var object= IsolatedStorageSettings.ApplicationSettings["State"] as PaymentItem;
//Remove the state now
IsolatedStorageSettings.ApplicationSettings.Remove("State");
IsolatedStorageSettings.ApplicationSettings.Save();
}
您可以在导航查询中使用某种相关信息进行导航
NavigationService.Navigate(new Uri("/ModifiedAddress.xaml?paymentId=1", UriKind.Relative));
然后在SomePage上解析该Id,并从某种存储库中获取PaymentItem
根据您提供的代码很难提供更多信息
第二个选项(更糟糕的一点)是通过App class共享项目,App class可以从所有页面访问。要在Aman的答案中添加一些选项: 您还可以通过导航事件向站点传递变量。您可以通过覆盖页面的OnNavigatedFrom事件并向要传递内容的页面添加可访问属性来完成此操作 例如:
Page1.xaml.cs
protected override OnNavigatedFrom(...args... e)
{
if(e.Uri.OriginalString.Contains("Page2.xaml"))
{
((Page2)e.Content).SourceList = Page1LongListSelector.ItemSource;
}
}
然后第2页:
Page2.xaml.cs
public List<SomeObject> SourceList
{
get;
set;
}
....
Page2LongListSelector.ItemSource = SourceList;
....
Page2.xaml.cs
公共列表源列表
{
得到;
设置
}
....
Page2LongListSelector.ItemSource=SourceList;
....
之所以可以这样做,是因为在完成导航并构造第二个页面后调用OnNavigatedFrom事件。您可以尝试使用OnNavigatedTo方法获取正在导航的页面中的数据 阅读本文了解其工作原理: 下载此示例以探索代码后: 希望有帮助!你好
Page2.xaml.cs
public List<SomeObject> SourceList
{
get;
set;
}
....
Page2LongListSelector.ItemSource = SourceList;
....