我想访问我在主页面中创建的DeviceInformationCollection对象变量。加载应用程序并导航到另一个页面后,我想访问其他页面中的我的DeviceInformationCollection对象。我应该怎么想才能访问这个变量。
谢谢!
解决方案
Hi DeepakSOS,
欢迎来到开发通用Windows应用论坛!
请阅读粘贴帖子,特别是 引导发布:主题行标签 Windows 10 SDK和工具的已知问题 。
我们可以使用导航(类型,对象) t)方法,它使Frame加载由指定的Page表示的内容,同时传递一个参数,由导航的目标解释。
在另一个页面中,我们可以覆盖 OnNavigatedTo方法,并通过 NavigationEventArgs.Parameter property。
例如:
在主页面中:
DeviceInformationCollection设备; private async void Button_Click(object sender,RoutedEventArgs e) { devices = await DeviceInformation.FindAllAsync(selector); Frame rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(BlankPage1),devices); }在另一页中:
protected override void OnNavigatedTo(NavigationEventArgs e) { var infolist = e.Parameter as DeviceInformationCollection; }最好的问候,
Jayden Gu
Hi,
I want to accessDeviceInformationCollection object variable which i created in main page. after application is loaded and navigated to another page i want to access myDeviceInformationCollection object in other page. how should i suppose to acces this variable.
thanks !!
解决方案Hi DeepakSOS,
Welcome to the Developing Universal Windows apps forum!
Please read the sticky posts, especiallytheGuide to posting: subject line tagsandKnown Issues for Windows 10 SDK and Tools.
We can use theNavigate(Type, Object) method, it causes the Frame to load content represented by the specified Page, also passing a parameter to be interpreted by the target of the navigation.
And in the another page, we canoverride theOnNavigatedTo method, and get theDeviceInformationCollection by theNavigationEventArgs.Parameterproperty.
For example:
In the main page:
DeviceInformationCollection devices; private async void Button_Click(object sender, RoutedEventArgs e) { devices = await DeviceInformation.FindAllAsync(selector); Frame rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(BlankPage1), devices); }In the other page:
protected override void OnNavigatedTo(NavigationEventArgs e) { var infolist = e.Parameter as DeviceInformationCollection; }Best Regards,
Jayden Gu
更多推荐
如何在其他页面中访问DeviceInformationCollection
发布评论