2011年11月4日 星期五

Windows Metro style app 之 "Hello World!"

既然安裝了 Windows 8 Developer Preview ,不能免俗的 "Hello World!" 一下。 


本文是參考此篇:Getting started with Windows Metro style app development,加幾張圖給沒用過 Visual Studio 的朋友看。 
預裝的版本為:Windows 8 Developer Preview with developer tools English, 64-bit (x64),安裝方式請參考 Windows 8 Developer Preview 安裝 (一)。 


原文內文請自行參考,直接開始:
1. 點擊 [Visual Studio 11 Express]。


2. Visual Studio 11 Express 開起來後,點選 1 [New Project...],點擊 2 [Visual C#] --> [Windows Metro style],選擇 3 [Application],最後把 Project Name 改成 4 "Hello World"。 


3. 將以下程式碼輸入至 <Grid x:Name="LayoutRoot" Background="#FF0C0C0C"> </Grid>之間 (請不要偷懶,一個字母一個字母打)。打完之後,上方黑色窗格就會出現 [Click Me!] Button。 
-------------------------------------------------------------------------------------------------------------------------
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Button Grid.Row="0" Grid.Column="0" Name="myButton" Click="changeText">Click Me!</Button>
    <TextBox Grid.Row="1" Grid.Column="0" Name="myTextBox" />
-------------------------------------------------------------------------------------------------------------------------

4. 點擊兩下 [Click Me!] Button,就會出現 [MainPage.xaml.cs] code-behind 視窗。在紅色圈起來的地方加入以下程式碼 (最後分號不要忘)。
-------------------------------------------------------------------------------------------------------------------------
    myTextBox.Text = "Hello Windows Metro style apps with XAML!";
-------------------------------------------------------------------------------------------------------------------------

5. 按下鍵盤的 [F5],進入 Debug 模式,Hello World 程式就會出現了。按下 [Click Me!],下方就會出現 "Hello Windows Metro style apps with XAML!"。

6. 關閉程式。按下鍵盤的 [Win] 鍵 ( [Ctrl] 及 [Alt] 中間),回到主畫面,再點 [Visual Studio 11 Express],再同時按下鍵盤 [Shift] + [F5],就可以停止 Debug 模式。

主畫面拉到最右邊,可以看到剛才的程式。

沒有留言:

張貼留言