如何在其他页面中访问DeviceInformationCollection [英] How to access DeviceInformationCollection in other page

查看:90
本文介绍了如何在其他页面中访问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 access DeviceInformationCollection  object variable which i created in main page. after application is loaded and navigated to another page i want to access my DeviceInformationCollection 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, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools .

We can use the Navigate(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 can override the OnNavigatedTo method, and get the DeviceInformationCollection by the NavigationEventArgs.Parameter property.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆