如何在其他页面中访问DeviceInformationCollection

编程入门 行业动态 更新时间:2024-10-26 20:30:14
本文介绍了如何在其他页面中访问DeviceInformationCollection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想访问我在主页面中创建的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

本文发布于:2023-11-16 21:51:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607614.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:页面   如何在   DeviceInformationCollection

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!