教學課程:使用 C 建立簡單的應用程式#Tutorial: Create a simple application with C#

藉由完成這個教學課程,讓自己更熟悉許多可在使用 Visual Studio 開發應用程式時運用的工具、對話方塊和設計工具。By completing this tutorial, you'll become familiar with many of the tools, dialog boxes, and designers that you can use when you develop applications with Visual Studio. 當您在學習如何使用整合式開發環境 (IDE) 時,您會建立簡單的 "Hello, World" 應用程式、設計 UI、新增程式碼,以及進行偵錯。You'll create a "Hello, World" application, design the UI, add code, and debug errors, while you learn about working in the integrated development environment (IDE).

先決條件Prerequisites

如果您尚未安裝 Visual Studio,請前往 Visual Studio 下載頁面免費進行安裝。If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.

  • 如果您尚未安裝 Visual Studio,請前往 Visual Studio 下載頁面免費進行安裝。If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
  • 您可以在本教學課程中使用 .NET Framework 或 .NET Core。You can use either .NET Framework or .NET Core for this tutorial. .NET Core 是較新且更新式的架構。.NET Core is the newer, more modern framework. .NET Core 需要 Visual Studio 2019 16.3 版或更新版本。.NET Core requires Visual Studio 2019 version 16.3 or later.

設定 IDEConfigure the IDE

當您第一次開啟 Visual Studio 時,系統會提示您登入。When you open Visual Studio for the first time, you'll be prompted to sign in. 這在此教學課程中為選擇性步驟。This step is optional for this tutorial. 接下來您可能會看到對話方塊,要求您選擇開發設定和色彩佈景主題。Next you may be shown a dialog box that asks you to choose your development settings and color theme. 保留預設值,然後選擇 [啟動 Visual Studio]****。Keep the defaults and choose Start Visual Studio.

選擇設定對話方塊

Visual Studio 啟動後,您會看到工具視窗、功能表和工具列,以及主視窗空間。After Visual Studio launches, you'll see tool windows, the menus and toolbars, and the main window space. 工具視窗會停駐在應用程式視窗的左右端,同時 [ 快速啟動]、功能表列和標準工具列則位於視窗的上方。Tool windows are docked on the left and right sides of the application window, with Quick Launch, the menu bar, and the standard toolbar at the top. 位於應用程式視窗中央的是 [ 起始頁]。In the center of the application window is the Start Page. 當您載入方案或專案時,編輯器和設計工具會出現在 [起始頁] **** 所在的空間中。When you load a solution or project, editors and designers appear in the space where the Start Page is. 在開發應用程式時,您大部分時間都會在此中央區域工作。When you develop an application, you'll spend most of your time in this central area.

Visual Studio 已套用一般設定的 2017 IDEVisual Studio 2017 IDE with General Settings applied

當您啟動 Visual Studio 時,會先開啟 [開始] 視窗。When you launch Visual Studio, the start window opens first. 選取 [不使用程式碼繼續]**** 以開啟開發環境。Select Continue without code to open the development environment. 您會看到工具視窗、功能表和工具列,以及主視窗空間。You'll see tool windows, the menus and toolbars, and the main window space. [工具] 視窗會停駐在應用程式視窗的左側和右側,搜尋方塊、功能表列和標準工具列則位於視窗上方。Tool windows are docked on the left and right sides of the application window, with a search box, the menu bar, and the standard toolbar at the top. 當您載入方案或專案時,編輯器和設計工具會出現在應用程式視窗的中央區域。When you load a solution or project, editors and designers appear in the central space of the application window. 在開發應用程式時,您大部分時間都會在此中央區域工作。When you develop an application, you'll spend most of your time in this central area.

建立專案Create the project

當您在 Visual Studio 中建立應用程式時,您需要先建立一個專案和一個方案。When you create an application in Visual Studio, you first create a project and a solution. 在這個範例中,您將建立 Windows Presentation Foundation (WPF) 專案。For this example, you'll create a Windows Presentation Foundation (WPF) project.

  1. 建立新專案。Create a new project. 在功能表列上 ,選取 [ 檔案 > 新增 > 專案]。On the menu bar, select File > New > Project.

    在功能表列上,選擇 [檔案]、[新增]、[專案]On the menu bar, choose File, New, Project

  2. 在 [新增專案]**** 對話方塊中,選取 [已安裝]**** > [Visual C#]**** > [Windows 桌面]**** 類別,然後選取 [WPF 應用程式 (.NET Framework)]**** 範本。In the New Project dialog, select the Installed > Visual C# > Windows Desktop category, and then select the WPF App (.NET Framework) template. 將專案命名為 HelloWPFApp,然後選取 [確定]****。Name the project HelloWPFApp, and select OK.

    Visual Studio [新增專案] 對話方塊中的 WPF 應用程式範本WPF app template in Visual Studio New Project dialog

  1. 開啟 Visual Studio 2019。Open Visual Studio 2019.

  2. 在開始視窗中,選擇 [建立新專案]****。On the start window, choose Create new project.

    檢視 [建立新專案] 視窗View the 'Create a new project' window

  3. 在 [ 建立新專案 ] 畫面上,搜尋 "wpf",選擇 [ **wpf 應用程式 ( .net Core]) **,然後選擇 [下一步]On the Create a new project screen, search for "WPF," choose WPF App (.NET Core), and then choose Next.

    [建立新專案] 對話方塊中的 WPF 應用程式範本WPF app template in 'Create a new project' dialog

    注意

    您可能會發現兩個 WPF 桌面範本,一個用於 .NET Framework,另一個用於 .NET Core。You might find two WPF desktop templates, one for .NET Framework and another for .NET Core. .NET Core 範本可在 Visual Studio 2019 16.3 版和更新版本中使用。The .NET Core template is available in Visual Studio 2019 version 16.3 and later. 您可以在本教學課程中使用其中一個,但建議您針對新的開發使用 .NET Core。You can use either one for this tutorial, but we recommend .NET Core for new development.

  4. 在下一個畫面上,為專案指定名稱 HelloWPFApp,然後選擇 [建立]****。At the next screen, give the project a name, HelloWPFApp, and choose Create.

    將您的專案命名為 ' HelloWPFApp 'Name your project 'HelloWPFApp'

Visual Studio 會建立 HelloWPFApp 專案和方案,而且方案總管會顯示各種不同檔案。Visual Studio creates the HelloWPFApp project and solution, and Solution Explorer shows the various files. WPF 設計工具會在分割檢視中顯示 MainWindow.xaml 的設計檢視和 XAML 檢視。The WPF Designer shows a design view and a XAML view of MainWindow.xaml in a split view. 您可以滑動分隔器來增加或減少顯示任一檢視。You can slide the splitter to show more or less of either view. 您可以選擇只查看視覺檢視,或只查看 XAML 檢視。You can choose to see only the visual view or only the XAML view.

IDE 中的 WPF 專案和方案WPF project and solution in the IDE

注意

如需 XAML (eXtensible Application Markup Language) 的詳細資訊,請參閱 WPF 的 XAML 概觀頁面。For more information about XAML (eXtensible Application Markup Language), see the XAML overview for WPF page.

建立專案之後,您可以進行自訂。After you create the project, you can customize it. 若要這麼做,請選擇 [檢視]**** 功能表中的 [屬性]**** 視窗,或按 F4To do so, choose Properties Window from the View menu, or press F4. 然後,您可以顯示和變更應用程式中專案項目、控制項及其他項目的選項。Then, you can display and change options for project items, controls, and other items in an application.

屬性視窗Properties window

變更 MainWindow.xaml 的名稱Change the name of MainWindow.xaml

讓我們給 MainWindow 一個更具體的名稱。Let's give MainWindow a more specific name. 方案總管中,以滑鼠右鍵按一下 MainWindow ,然後選擇 [ 重新命名]。In Solution Explorer, right-click on MainWindow.xaml and choose Rename. 將檔案重新命名為 問候. xamlRename the file to Greetings.xaml.

設計使用者介面 (UI)Design the user interface (UI)

如果設計工具未開啟,請選取 [問候語],然後按Shift + F7以開啟設計工具。If the designer is not open, select Greetings.xaml and press Shift+F7 to open the designer.

我們會將三種類型的控制項新增至這個應用程式:一個 TextBlock 控制項、兩個 RadioButton 控制項和一個 Button 控制項。We'll add three types of controls to this application: a TextBlock control, two RadioButton controls, and a Button control.

新增 TextBlock 控制項Add a TextBlock control

  1. 按下Ctrl + Q以啟動搜尋方塊,然後輸入 [工具箱]。Press Ctrl+Q to activate the search box and type Toolbox. 從結果清單中選擇 [檢視] > [工具箱]****。Choose View > Toolbox from the results list.

  2. 在 [工具箱]**** 中展開 [通用 WPF 控制項]**** 節點以查看 TextBlock 控制項。In the Toolbox, expand the Common WPF Controls node to see the TextBlock control.

    已反白顯示 [TextBlock] 控制項的 [工具箱]Toolbox with the TextBlock control highlighted

  3. 選擇 TextBlock 項目並將它拖曳至設計介面上的視窗,即可將 TextBlock 控制項加入設計介面。Add a TextBlock control to the design surface by choosing the TextBlock item and dragging it to the window on the design surface. 將控制項置中靠近視窗頂端。Center the control near the top of the window. 在 Visual Studio 2019 和更新版本中,您可以使用紅色的指導方針來將控制項置中。In Visual Studio 2019 and later, you can use the red guidelines to center the control.

    您的視窗應該會和下圖類似:Your window should resemble the following illustration:

    問候表單上的 [TextBlock] 控制項TextBlock control on the Greetings form

    XAML 標記應該看起來與下列範例相似:The XAML markup should look something like the following example:

    <Grid>
        <TextBlock HorizontalAlignment="Left" Margin="387,60,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>
    </Grid>
    

自訂文字區塊中的文字Customize the text in the text block

  1. 在 XAML 檢視中,找出 TextBlock 的標記並將 Text 屬性從 TextBox 變更為 Select a message option and then choose the Display button.In the XAML view, locate the markup for TextBlock and change the Text attribute from TextBox to Select a message option and then choose the Display button.

    XAML 標記應該看起來與下列範例相似:The XAML markup should look something like the following example:

    <Grid>
        <TextBlock HorizontalAlignment="Left" Margin="387,60,0,0" TextWrapping="Wrap" Text="Select a message option and then choose the Display button." VerticalAlignment="Top"/>
    </Grid>
    
  2. 視需要再次將 TextBlock 置中,然後按 Ctrl+S 或使用 [檔案]**** 功能表項目來儲存您的變更。Center the TextBlock again if you like, and then save your changes by pressing Ctrl+S or using the File menu item.

接下來,您要將兩個 選項按鈕 控制項加入表單中。Next, you'll add two RadioButton controls to the form.

新增選項按鈕Add radio buttons

  1. 在 [工具箱]**** 中,尋找 RadioButton 控制項。In the Toolbox, find the RadioButton control.

    已選取 [RadioButton] 控制項的 [工具箱] 視窗Toolbox window with RadioButton control selected

  2. 選擇 RadioButton 項目並將它拖曳至設計介面的視窗,即可將兩個 RadioButton 控制項新增至設計介面。Add two RadioButton controls to the design surface by choosing the RadioButton item and dragging it to the window on the design surface. 移動按鈕 (選取它們並使用方向鍵),讓按鈕並排顯示於 TextBlock 控制項下。Move the buttons (by selecting them and using the arrow keys) so that the buttons appear side by side under the TextBlock control. 使用紅色的指導方針來對齊控制項。Use the red guidelines to align the controls.

    您的視窗應該會像這樣:Your window should look like this:

    具有 TextBlock 和兩個選項按鈕的問候表單Greetings form with TextBlock and two radio buttons

  3. 在左側 RadioButton 控制項的 [ 屬性 ] 視窗中,將 [ 名稱 ] 屬性 (在 [ 屬性 ] 視窗頂端的屬性) 變更為 HelloButtonIn the Properties window for the left RadioButton control, change the Name property (the property at the top of the Properties window) to HelloButton.

    RadioButton 的 [屬性] 視窗RadioButton properties window

  4. 在右邊 RadioButton 控制項的 [屬性]**** 視窗中,將 [名稱]**** 屬性變更為 GoodbyeButton,然後儲存您的變更。In the Properties window for the right RadioButton control, change the Name property to GoodbyeButton, and then save your changes.

接下來,您將會為每個 RadioButton 控制項加入顯示文字。Next, you'll add display text for each RadioButton control. 下列步驟會更新 RadioButton 控制項的 [ 內容 ] 屬性。The following procedure updates the Content property for a RadioButton control.

為每個選項按鈕新增顯示的文字Add display text for each radio button

  1. 在 XAML 中,將和的 內容 屬性更新為 HelloButton GoodbyeButton "Hello""Goodbye"Update the Content attribute for the HelloButton and GoodbyeButton to "Hello" and "Goodbye" in the XAML. XAML 標記現在看起來應該會類似下列範例:The XAML markup should now look similar to the following example:

    <Grid>
         <TextBlock HorizontalAlignment="Left" Margin="252,47,0,0" TextWrapping="Wrap" Text="Select a message option and then choose the Display button." VerticalAlignment="Top"/>
         <RadioButton x:Name="HelloButton" Content="Hello" HorizontalAlignment="Left" Margin="297,161,0,0" VerticalAlignment="Top"/>
         <RadioButton x:Name="GoodbyeButton" Content="Goodbye" HorizontalAlignment="Left" Margin="488,161,0,0" VerticalAlignment="Top"/>
    </Grid>
    

設定預設勾選的選項按鈕Set a radio button to be checked by default

在此步驟中,我們會設定預設勾選 HelloButton,這樣就一律會選取兩個選項按鈕的其中一個。In this step, we'll set HelloButton to be checked by default so that one of the two radio buttons is always selected.

  1. 在 XAML 檢視中,找出 HelloButton 的標記。In the XAML view, locate the markup for HelloButton.

  2. 加入 IsChecked 屬性,並將它設定為 TrueAdd an IsChecked attribute and set it to True. 具體而言,請新增 IsChecked="True"Specifically, add IsChecked="True".

    XAML 標記現在看起來應該會類似下列範例:The XAML markup should now look similar to the following example:

    <Grid>
         <TextBlock HorizontalAlignment="Left" Margin="252,47,0,0" TextWrapping="Wrap" Text="Select a message option and then choose the Display button." VerticalAlignment="Top"/>
         <RadioButton x:Name="HelloButton" Content="Hello" IsChecked="True" HorizontalAlignment="Left" Margin="297,161,0,0" VerticalAlignment="Top"/>
         <RadioButton x:Name="GoodbyeButton" Content="Goodbye" HorizontalAlignment="Left" Margin="488,161,0,0" VerticalAlignment="Top"/>
    </Grid>
    

您將加入的最後一個 UI 元素是 按鈕 控制項。The final UI element that you'll add is a Button control.

新增按鈕控制項Add the button control

  1. 在 [工具箱]**** 中尋找 Button 控制項,然後將它拖曳至設計檢視中的表單,將它新增至設計介面的 RadioButton 控制項底下。In the Toolbox, find the Button control, and then add it to the design surface under the RadioButton controls by dragging it to the form in the design view. 如果您使用 Visual Studio 2019 或更新版本,則會有一條紅線可協助您將控制項置中。If you're using Visual Studio 2019 or later, a red line helps you center the control.

  2. 在 XAML 檢視中,將 Button 控制項的 [內容]**** 值從 Content="Button" 變更為 Content="Display",然後儲存變更。In the XAML view, change the value of Content for the Button control from Content="Button" to Content="Display", and then save the changes.

    您的視窗應該會和下圖類似。Your window should resemble the following illustration.

    具有控制項標籤的問候表單Greetings form with control labels

    XAML 標記現在看起來應該會類似下列範例:The XAML markup should now look similar to the following example:

    <Grid>
         <TextBlock HorizontalAlignment="Left" Margin="252,47,0,0" TextWrapping="Wrap" Text="Select a message option and then choose the Display button." VerticalAlignment="Top"/>
         <RadioButton x:Name="HelloButton" Content="Hello" IsChecked="True" HorizontalAlignment="Left" Margin="297,161,0,0" VerticalAlignment="Top"/>
         <RadioButton x:Name="GoodbyeButton" Content="Goodbye" HorizontalAlignment="Left" Margin="488,161,0,0" VerticalAlignment="Top"/>
         <Button Content="Display" HorizontalAlignment="Left" Margin="377,270,0,0" VerticalAlignment="Top" Width="75"/>
    </Grid>
    

將程式碼新增至顯示按鈕Add code to the display button

此應用程式執行時,會在使用者選擇選項按鈕並選擇 [顯示]**** 按鈕之後顯示訊息方塊。When this application runs, a message box appears after a user chooses a radio button and then chooses the Display button. 一個訊息方塊會顯示 Hello,而另外一個會顯示 Goodbye。One message box will appear for Hello, and another will appear for Goodbye. 若要建立這個行為,您必須將程式碼新增至 Greetings.xaml.cs 中的 Button_Click 事件。To create this behavior, you'll add code to the Button_Click event in Greetings.xaml.cs.

  1. 在設計介面上,按兩下 [ 顯示 ] 按鈕。On the design surface, double-click the Display button.

    Greetings.xaml.cs 隨即開啟,並將游標置於 Button_Click 事件中。Greetings.xaml.cs opens, with the cursor in the Button_Click event.

    private void Button_Click(object sender, RoutedEventArgs e)
    {
    
    }
    
  2. 輸入下列程式碼:Enter the following code:

    if (HelloButton.IsChecked == true)
    {
         MessageBox.Show("Hello.");
    }
    else if (GoodbyeButton.IsChecked == true)
    {
        MessageBox.Show("Goodbye.");
    }
    
  3. 儲存應用程式。Save the application.

偵錯和測試應用程式Debug and test the application

接下來,您會偵錯應用程式以尋找錯誤,並測試兩個訊息方塊是否都正確出現。Next, you'll debug the application to look for errors and test that both message boxes appear correctly. 下列指示會告訴您如何建置和啟動偵錯工具,不過您稍後也可閱讀 建置 WPF 應用程式 (WPF)對 WPF 進行偵錯以取得詳細資訊。The following instructions tell you how to build and launch the debugger, but later you might read Build a WPF application (WPF) and Debug WPF for more information.

尋找和修正錯誤Find and fix errors

在此步驟中,您將會發現我們先前藉由變更 MainWindow .xaml 檔案的名稱所造成的錯誤。In this step, you'll find the error that we caused earlier by changing the name of the MainWindow.xaml file.

開始偵錯並找出錯誤Start debugging and find the error

  1. F5 或依序選取 [偵錯]**** 和 [開始偵錯]****,來啟動偵錯工具。Start the debugger by pressing F5 or selecting Debug, then Start Debugging.

    [中斷模式]**** 視窗隨即出現,而 [輸出]**** 視窗會指出發生了 IOException:找不到資源 'mainwindow.xaml'。A Break Mode window appears, and the Output window indicates that an IOException has occurred: Cannot locate resource 'mainwindow.xaml'.

    IOException 訊息IOException message

  2. 選擇 [ Debug停止錯] 以停止偵錯工具 > ** **。Stop the debugger by choosing Debug > Stop Debugging.

我們已在這個教學課程開始時,將 MainWindow.xaml 重新命名為 Greetings.xaml,但程式碼仍會參考 MainWindow.xaml 作為應用程式的啟動 URI,因此專案無法啟動。We renamed MainWindow.xaml to Greetings.xaml at the start of this tutorial, but the code still refers to MainWindow.xaml as the startup URI for the application, so the project can't start.

指定 Greetings.xaml 作為啟動 URISpecify Greetings.xaml as the startup URI

  1. 在 [方案總管]**** 中,開啟 App.xaml 檔。In Solution Explorer, open the App.xaml file.

  2. StartupUri="MainWindow.xaml" 變更為 StartupUri="Greetings.xaml",然後儲存變更。Change StartupUri="MainWindow.xaml" to StartupUri="Greetings.xaml", and then save the changes.

再次啟動偵錯工具 (按 F5)。Start the debugger again (press F5). 您應該會看到應用程式的 問候語 視窗。You should see the Greetings window of the application.

正在執行的應用程式螢幕擷取畫面

正在執行的應用程式螢幕擷取畫面

立即關閉應用程式視窗停止偵錯。Now close the application window to stop debugging.

使用中斷點進行偵錯Debug with breakpoints

新增一些中斷點,即可在偵錯時測試程式碼。You can test the code during debugging by adding some breakpoints. 若要加入中斷點,您可以選擇 [ Debug > 切換中斷點],方法是在編輯器的左邊界中,按一下您想要發生中斷的程式程式碼旁邊,或是按F9You can add breakpoints by choosing Debug > Toggle Breakpoint, by clicking in the left margin of the editor next to the line of code where you want the break to occur, or by pressing F9.

新增中斷點Add breakpoints

  1. 開啟 Greetings.xaml.cs,然後選取下列程式程式碼: MessageBox.Show("Hello.")Open Greetings.xaml.cs, and select the following line: MessageBox.Show("Hello.")

  2. 依序選取 [ 偵錯] 和 [ 切換中斷點],以新增中斷點。Add a breakpoint from the menu by selecting Debug, then Toggle Breakpoint.

    在編輯器視窗最左緣、程式碼行的旁邊會出現一個紅色圓圈。A red circle appears next to the line of code in the far left margin of the editor window.

  3. 請選取下列程式碼行: MessageBox.Show("Goodbye.")Select the following line: MessageBox.Show("Goodbye.").

  4. F9 鍵新增中斷點,然後按 F5 開始偵錯。Press the F9 key to add a breakpoint, and then press F5 to start debugging.

  5. 在 [ Greetings ] 視窗中,選擇 [ Hello ] 選項按鈕,然後選擇 [ 顯示 ] 按鈕。In the Greetings window, choose the Hello radio button, and then choose the Display button.

    程式碼行 MessageBox.Show("Hello.") 會以黃色反白顯示。The line MessageBox.Show("Hello.") is highlighted in yellow. 在 IDE 底部,[自動變數]、[區域變數] 和 [監看式] 視窗會一起停駐在左邊,而 [呼叫堆疊]、[中斷點]、[例外狀況設定]、[命令]、[即時運算] 和 [輸出] 視窗會一起停駐在右邊。At the bottom of the IDE, the Autos, Locals, and Watch windows are docked together on the left side, and the Call Stack, Breakpoints, Exception Settings, Command, Immediate, and Output windows are docked together on the right side.

    偵錯工具中的中斷點Breakpoint in the debugger

  6. 在功能表列上,選擇 [ Debug > 跳出]。On the menu bar, choose Debug > Step Out.

    應用程式會繼續執行,而且會顯示含有文字 "Hello" 的訊息方塊。The application resumes execution, and a message box with the word "Hello" appears.

  7. 選擇訊息方塊上的 [ 確定 ] 按鈕將它關閉。Choose the OK button on the message box to close it.

  8. 在 [ Greetings ] 視窗中,選擇 [ Goodbye ] 選項按鈕,然後選擇 [ 顯示 ] 按鈕。In the Greetings window, choose the Goodbye radio button, and then choose the Display button.

    程式碼行 MessageBox.Show("Goodbye.") 會以黃色反白顯示。The line MessageBox.Show("Goodbye.") is highlighted in yellow.

  9. 選擇 F5 鍵繼續偵錯。Choose the F5 key to continue debugging. 當訊息方塊出現時,選擇訊息方塊中的 [ 確定 ] 按鈕關閉它。When the message box appears, choose the OK button on the message box to close it.

  10. 關閉應用程式視窗停止偵錯。Close the application window to stop debugging.

  11. 在功能表列上,選擇 [ Debug > 停用所有中斷點]。On the menu bar, choose Debug > Disable All Breakpoints.

查看 UI 元素的標記法View a representation of the UI elements

在執行中的應用程式中,您應該會看到顯示在視窗頂端的小工具。In the running app, you should see a widget that appears at the top of your window. 這是執行時間協助程式,可讓您快速存取某些實用的偵錯工具功能。This is a runtime helper that provides quick access to some helpful debugging features. 按一下第一個按鈕, 移至 [即時視覺化樹狀結構]。Click on the first button, Go to Live Visual Tree. 您應該會看到一個具有樹狀結構的視窗,其中包含頁面的所有視覺元素。You should see a window with a tree that contains all the visual elements of your page. 展開節點以尋找您新增的按鈕。Expand the nodes to find the buttons you added.

即時視覺化樹狀結構視窗的螢幕擷取畫面

建置應用程式的發行版本Build a release version of the application

既然已經驗證應用程式的運作一切正常,您就可以準備其發行組建。Now that you've verified that everything works, you can prepare a release build of the application.

  1. 在主功能表上,選取 [建立 > 清除方案],以刪除在先前組建期間建立的中繼檔案和輸出檔案。On the main menu, select Build > Clean solution to delete intermediate files and output files that were created during previous builds. 這並非必要動作,但它可清除偵錯組建輸出。This isn't necessary, but it cleans up the debug build outputs.

  2. 使用工具列上的下拉式控制項,將 HelloWPFApp 的組建設定從 Debug 變更為 Release , (它會顯示目前) 的 "Debug"。Change the build configuration for HelloWPFApp from Debug to Release by using the dropdown control on the toolbar (it says "Debug" currently).

  3. 選擇 [組建 > 組建方案] 來建立方案。Build the solution by choosing Build > Build Solution.

恭喜您完成此教學課程!Congratulations on completing this tutorial! 您可以在方案和專案目錄下找到您所建立的 .exe (..\HelloWPFApp\HelloWPFApp\bin\Release) 。You can find the .exe you built under your solution and project directory (...\HelloWPFApp\HelloWPFApp\bin\Release).

後續步驟Next steps

恭喜您完成此教學課程!Congratulations on completing this tutorial! 若要更深入了解,請繼續下列教學課程。To learn even more, continue with the following tutorials.

另請參閱See also