gpt4 book ai didi

c# - 如何将对象列表从我的 MainPage.xaml 发送到另一个页面

转载 作者:行者123 更新时间:2023-12-03 19:00:53 26 4
gpt4 key购买 nike

当导航到另一个页面时,如何使我的对象列表对另一个页面可用。

例如在我的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com