Development of New Fashion Windows 8 (8): Getting device information

Source: Internet
Author: User

Old Zhou's blogHttp://blog.csdn.net/tcjiaan, Reprinted please indicate the original author and source.

 

To obtain the device ID, name, and thumbnail of the current machine, we need to use the deviceinformation class (located in the windows. devices. Enumeration namespace ).

The usage is as follows:

1. Use the deviceinformation. findallasync static method to obtain a collection of deviceinformationcollections.

2. You can access all the members in the Set foreach. It is not hard to understand.

3. Obtain the identifier of the device based on the ID attribute of the deviceinformation object.

4. Obtain the device name from the name attribute.

5. The getthumbnailasync method gets the thumbnails of the device.

 

Does it seem simple? Next, we will use an instance to deepen the process.

1. Start Vs and create a project (38 words are omitted here ).

2. Declare a listview in the root grid of the home page to display the obtained device information. The XAML is as follows:

<Grid background = "{staticresource applicationpagebackgroundthemebrush}"> <listview name = "lvdevices" margin = "10" selectionmode = "NONE"> <listview. itemspanel> <itemspaneltemplate> <wrapgrid orientation = "horizontal" maximumrowsorcolumns = "3" itemwidth = "420"/> </itemspaneltemplate> </listview. itemspanel> </listview> </GRID>

4. Right-click the XAML document view and select view from the pop-up menu.CodeSwitch to the C # Code view, and then add the following code to the override onnavigatedto method:

Protected async override void onnavigatedto (navigationeventargs e) {deviceinformationcollection DCL = await deviceinformation. findallasync (); this. lvdevices. items. clear (); foreach (VAR item in DCL) {// item content layout grid itemroot = new grid (); itemroot. margin = New thickness (15); itemroot. columndefinitions. add (New columndefinition {width = gridlength. auto}); itemroot. columndefinitions. add (New columndefinition {width = new gridlength (1, gridunittype. star)}); // get the devicethumbnail thumb = await item. getthumbnailasync (); bitmapimage BMP = new bitmapimage (); thumb. seek (0); BMP. setsource (Thumb); // display image myimage = new image (); myimage. width = 80; myimage. height = 80; myimage. stretch = stretch. uniform; myimage. margin = New thickness (10); myimage. horizontalalignment = windows. UI. XAML. horizontalalignment. center; myimage. verticalalignment = windows. UI. XAML. verticalalignment. top; myimage. source = BMP; grid. setcolumn (myimage, 0); itemroot. children. add (myimage); // display text textblock textbl = new textblock (); textbl. textwrapping = textwrapping. wrap; run myruntitle = new run (); myruntitle. TEXT = item. name; myruntitle. fontsize = 20; myruntitle. fontweight = fontweights. bold; textbl. inlines. add (myruntitle); textbl. inlines. add (New linebreak (); run runid = new run () {text = item. id}; textbl. inlines. add (runid); grid. setcolumn (textbl, 1); itemroot. children. add (textbl); listviewitem lvitem = new listviewitem (); // lvitem. width = 600; lvitem. content = itemroot; // Add the item to listview this. lvdevices. items. add (lvitem );}}

The above code is a simple example. If you are familiar with WPF, you don't need to read the following content.

Because the content to be displayed is a bit complex and contains thumbnails and text, a grid is used as the content of listviewitem.

This grid is divided into two columns. The first column is the image control, and the second column is the textblock control that displays text information. In textblock, the document object is used. Both texts are run objects, and a line break is used in the middle.

The first run shows the device name, bold; the second run does not have any modifier, common text, display ID.

 

Is the running result.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.