Using C + + in Visual Studio to develop Metro application _c language

Source: Internet
Author: User
Tags visual studio

The Visual Studio 11 consumer preview supports the use of C + + to create Metro-style applications, which is a big news for local application developers. Here we will create a very simple Metro application.

Start Visual Studio and create a project from the visual C++>windows Metro Style>blank application template.

"Hello World"

Open the Blankpage.xaml file, scroll to the bottom of the code and locate the Grid element, then insert a TextBlock, as follows:

Copy Code code as follows:
<grid background= "{StaticResource Applicationpagebackgroundbrush}" >
<textblock text= "Hello World" margin= "12,20" style= "{StaticResource Subheadertextstyle}"/>
</Grid>

The Margin property is the distance between the text from the boundary, where we set the left distance of 12px, and the top of the distance is 20px. You can also modify the FontSize property value to change the font size.

If you run the application now, it will be a black screen showing Hello world text in the upper left corner. You can define the UI appearance of the application by Blankpage.xaml, but the code logic is stored in the blankpage.xaml.h and BlankPage.xaml.cpp files, and the two files are placed in the same directory as the Blankpage.xaml.

This is an ordinary C + + class, but different, there are some new extended grammars that become c++/cx, meaning Component extensions. Pure C + + cannot be used to develop Metro apps, but using pure WinRT can make code cumbersome because all of the Metro world are COM objects. C++/CX extensions can give C + + programmers no need to know too many non-standard extensions. More technical details can be hidden by the ADDREF and release calls.


C + to XAML

You can name the TextBlock defined in XAML by adding x:name= "Txthello" and set the value. You can then use the following code to manipulate the text element. Add the following code to the Blankpage::onnavigatedto method:

 
Txthello->text = "Hello world!!!";

Running the program, you will see the results shown in the following figure:

Although the above example is not worth getting excited about, it is very easy to think about how you learned Win32, MFC and WTL development.

Related Article

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.