在我的Windows Phone应用程序中,我使用来自web api的数据填充longlistselector并使用
将数据输入到类中 private void NewDownloaded(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Result == null || e.Error != null)
{
MessageBox.Show("There was an error connecting to the server");
}
else
{
XDocument loadedData = XDocument.Parse(e.Result);
var data = from query in loadedData.Descendants("pattern")
select new newpatterns
{
ID = (string)query.Element("id"),
Title = (string)query.Element("title"),
UserName = (string)query.Element("userName"),
DateCreated = (string)query.Element("dateCreated"),
Url = (string)query.Element("Url"),
};
newlonglist.ItemsSource = data.ToList();
}
}
然后当在长列表选择器中选择项目时,我导航到第二页面。使用
private void newlonglist_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
LongListSelector selector = sender as LongListSelector;
if (selector == null)
return;
newpatterns newdata = selector.SelectedItem as newpatterns;
if (newdata == null)
return;
//MessageBox.Show(newdata.Hex);
NavigationService.Navigate(new Uri("/NewImagePage.xaml?id=" + newdata.ID, UriKind.Relative));
newlonglist.SelectedItem = null;
}
我的问题是在第二页“NewImagePage.xaml”中我想找到从ID中调用这个选中的项目所以我可以得到其余的数据,有没有办法做到这一点而不通过它全部作为查询字符串..
谢谢..
答案 0 :(得分:1)
是的,有不同的方法,例如:
基本上一切都取决于代码的外观和想要实现的目标。
答案 1 :(得分:1)
您可以使用Windows Phone的IsolatedStorageSettings功能来完成您的工作。这是你的问题的解决方案。
private void newlonglist_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
IsolatedStorageSettings MemorySettings = IsolatedStorageSettings.ApplicationSettings;
LongListSelector selector = sender as LongListSelector;
if (selector == null)
return;
newpatterns newdata = selector.SelectedItem as newpatterns;
if (newdata == null)
return;
//MessageBox.Show(newdata.Hex);
MemorySettings.Add("SelectedItem",newdata );
NavigationService.Navigate(new Uri("/NewImagePage.xaml, UriKind.Relative));
}
在NewImagePage.xaml
protected override void OnNavigatedTo(NavigationEventArgs e)
{ IsolatedStorageSettings MemorySettings = IsolatedStorageSettings.ApplicationSettings;
if(MemorySettings.Contains("SelectedItem"))
{
newpatterns newdata = MemorySettings["SelectedItem"] as newpatterns ;
MemorySettings.Remove("SelectedItem");
}
}