作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当导航到另一个页面时,如何使我的对象列表对另一个页面可用。
例如在我的 mainpage.xaml 中
var data2 = from query in document.Descendants("weather")
select new Forecast
{
date = (string)query.Element("date"),
tempMaxC = (string)query.Element("tempMaxC"),
tempMinC = (string)query.Element("tempMinC"),
weatherIconUrl = (string)query.Element("weatherIconUrl"),
};
forecasts = data2.ToList<Forecast>();
....
NavigationService.Navigate(new Uri("/WeatherInfoPage.xaml", UriKind.Relative));
然后在我的其他类(class)中,我想让它可用,这样我就可以像这样使用它
private void AddPageItem(List<Forecast> forecasts)
{
..
}
最佳答案
这对你有帮助
//使用PhoneApplicationService.Current.State来存储列表//
PhoneApplicationService.Current.State["yourparam"] = lstpro.SelectedItems; NavigationService.Navigate(new Uri("/res.xaml", UriKind.Relative))
在第二页
私有(private)列表 iList1;
//在onNavigatedTo事件中将存储的列表赋值给变量//
protected 覆盖 void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
var i= PhoneApplicationService.Current.State["yourparam"];
//convert object to list//
iList1 = (IList) i ;
lstpro.ItemsSource = iList1;
}
关于c# - 如何将对象列表从我的 MainPage.xaml 发送到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19479451/
我是一名优秀的程序员,十分优秀!