[Win8] Windows 8 Development notes (III): code reading dynamic image generation page

Source: Internet
Author: User

Create a project called lianliankantest.

Create a folder named images to store images. Drag 10 images to the folder:



Open mainpage. XAML. CS and find the override onnavigatedto method. This method is called when you jump to the page, so we add dynamic page initialization here.

As mentioned above, rowdefinition and columndefinition are used to generate columns in the grid layout. In mainpage. XAML, we first define the grid name on the home page as homepage for background calls.

In mainpage. XAML. CS, find the override onnavigatedto method, and write the column definition that is dynamically added:

Protected override void onnavigatedto (navigationeventargs e) {for (INT I = 0; I <10; I ++) {rowdefinition ROW = new rowdefinition (); homepage. rowdefinitions. add (ROW) ;}for (INT I = 0; I <10; I ++) {columndefinition Col = new columndefinition (); homepage. columndefinitions. add (COL);} random = new random (); For (int row = 0; row <10; row ++) {for (INT Col = 0; col <10; Col ++) {image IMG = new image (); int num = random. next (1, 10); string filename = "MS-appx: // images/" + num + ". jpg "; // specifies the Image Element IMG. source = new bitmapimage (New uri (filename); // specify a row with a column named "Homepage. children. add (IMG); grid. setrow (IMG, row); grid. setcolumn (IMG, col );}}}

Here, MS-appx: // is used to specify the current path. If you are in a project, you must specify MS-appx :///.

Run the following command to view the page effect:


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.