Install Windows 8 Consumer Preview and Visual Studio 2011 Beta to develop a Metro-style application. First, write HelloWorld.
The Metro Style App supports multiple development methods, including:
☆Xaml/C # Or XAML/VB. Net
☆Html/JS
☆Xaml/C ++
☆Directx/C ++
You can also mix several technologies for development. I will try it with XAML/C # first.
1. Build a project
In the Win8 environment, Windows Metro style is displayed during project creation. This option is invisible in non-Win8 environments. Create a Blank Application, which is the simplest.
650) this. width = 650; "border =" 0 "alt =" "width =" 640 "height =" 480 "src =" http://www.bkjia.com/uploads/allimg/131228/1J551A55-0.png "/>
2. Write interface xamlblkpage. xaml)
Put only two textblocks to display text information.
- <Page
- X: Class = "HelloWorld. BlankPage"
- Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
- Xmlns: local = "using: HelloWorld"
- Xmlns: d = "http://schemas.microsoft.com/expression/blend/2008"
- Xmlns: mc = "http://schemas.openxmlformats.org/markup-compatibility/2006"
- Mc: Ignorable = "d">
-
- <Grid Background = "{StaticResource ApplicationPageBackgroundBrush}">
- <StackPanel>
- <! -- Put two textblocks on the interface, one displaying Hello World and the other displaying time -->
- <TextBlock FontSize = "60" HorizontalAlignment = "Center" Margin = "0,200,"> Hello World! </TextBlock>
- <TextBlock Name = "txtCurrentTime" FontSize = "48" HorizontalAlignment = "Center" Margin = ","> </TextBlock>
- </StackPanel>
- </Grid>
- </Page>
3. Write the code "BlankPage. xaml. cs)
Write several lines of code in the OnNavigatedTo method to display the current time in the second TextBlock on the interface.
- Protected override void OnNavigatedTo (NavigationEventArgs e)
- {
- // Create a timer. Update the Text of txtCurrentTime every second to the current time.
- Var timer = new DispatcherTimer ();
- Timer. Interval = TimeSpan. FromSeconds (1 );
- Timer. Tick + = (sender, args) => {
- TxtCurrentTime. Text = DateTime. Now. ToString ();
- };
- Timer. Start ();
- }
OK. Run Ctrl + F5. The effect is as follows:
650) this. width = 650; "border =" 0 "alt =" "width =" 320 "height =" 240 "style =" border: 1px solid # ccc "src =" http://www.bkjia.com/uploads/allimg/131228/1J551C41-1.png "/>
PS: To develop a Metro application on Win8, you must register a developer license first.
This article from the rabbit nest blog, please be sure to keep this source http://boytnt.blog.51cto.com/966121/859804