From fb0c8caad283ffa3fe18de548c24553c91f60e82 Mon Sep 17 00:00:00 2001 From: Andy De George <67293991+adegeo@users.noreply.github.com> Date: Tue, 2 Feb 2021 20:25:07 -0800 Subject: [PATCH] Add new create wpf app article (#193) --- .../get-started/create-app-visual-studio.md | 247 ++++++++++++++++++ .../create-app-visual-studio/app-default.png | Bin 0 -> 4120 bytes .../create-app-visual-studio/app-finished.png | Bin 0 -> 4294 bytes .../vs-config-new-project-next.png | Bin 0 -> 16108 bytes .../vs-config-new-project.png | Bin 0 -> 22195 bytes .../vs-create-new-project.png | Bin 0 -> 39260 bytes .../vs-designer-grid-rows-columns-label.png | Bin 0 -> 8963 bytes .../vs-designer-grid-rows-columns.png | Bin 0 -> 8227 bytes .../vs-main-window.pdn | Bin 0 -> 93658 bytes .../vs-main-window.png | Bin 0 -> 68074 bytes .../vs-template-search-cs.png | Bin 0 -> 50662 bytes .../vs-template-search-vb.png | Bin 0 -> 50920 bytes .../vs-template-search.png | Bin 0 -> 50915 bytes .../create-app-visual-studio/csharp/App.xaml | 9 + .../csharp/App.xaml.cs | 17 ++ .../csharp/AssemblyInfo.cs | 10 + .../csharp/Final.xaml | 30 +++ .../csharp/Final.xaml.cs | 35 +++ .../csharp/LayoutStep1.xaml | 12 + .../csharp/LayoutStep1.xaml.cs | 27 ++ .../csharp/LayoutStep2.xaml | 22 ++ .../csharp/LayoutStep2.xaml.cs | 27 ++ .../csharp/LayoutStep3.xaml | 24 ++ .../csharp/LayoutStep3.xaml.cs | 27 ++ .../csharp/LayoutStep4.xaml | 24 ++ .../csharp/LayoutStep4.xaml.cs | 27 ++ .../csharp/MoreControls1.xaml | 25 ++ .../csharp/MoreControls1.xaml.cs | 27 ++ .../csharp/MoreControls2.xaml | 38 +++ .../csharp/MoreControls2.xaml.cs | 27 ++ .../csharp/MoreControls3.xaml | 32 +++ .../csharp/MoreControls3.xaml.cs | 34 +++ .../csharp/Names.csproj | 9 + .../csharp/Start.xaml | 12 + .../csharp/Start.xaml.cs | 28 ++ .../vb/Application.xaml | 9 + .../vb/Application.xaml.vb | 6 + .../vb/AssemblyInfo.vb | 11 + .../create-app-visual-studio/vb/Final.xaml | 30 +++ .../create-app-visual-studio/vb/Final.xaml.vb | 9 + .../vb/MoreControls3.xaml | 32 +++ .../vb/MoreControls3.xaml.vb | 7 + .../create-app-visual-studio/vb/Names.vbproj | 22 ++ dotnet-desktop-guide/net/wpf/toc.yml | 2 +- 44 files changed, 897 insertions(+), 1 deletion(-) create mode 100644 dotnet-desktop-guide/net/wpf/get-started/create-app-visual-studio.md create mode 100644 dotnet-desktop-guide/net/wpf/get-started/media/create-app-visual-studio/app-default.png create mode 100644 dotnet-desktop-guide/net/wpf/get-started/media/create-app-visual-studio/app-finished.png create mode 100644 dotnet-desktop-guide/net/wpf/get-started/media/create-app-visual-studio/vs-config-new-project-next.png create mode 100644 dotnet-desktop-guide/net/wpf/get-started/media/create-app-visual-studio/vs-config-new-project.png create mode 100644 dotnet-desktop-guide/net/wpf/get-started/media/create-app-visual-studio/vs-create-new-project.png create mode 100644 dotnet-desktop-guide/net/wpf/get-started/media/create-app-visual-studio/vs-designer-grid-rows-columns-label.png create mode 100644 dotnet-desktop-guide/net/wpf/get-started/media/create-app-visual-studio/vs-designer-grid-rows-columns.png create mode 100644 dotnet-desktop-guide/net/wpf/get-started/media/create-app-visual-studio/vs-main-window.pdn create mode 100644 dotnet-desktop-guide/net/wpf/get-started/media/create-app-visual-studio/vs-main-window.png create mode 100644 dotnet-desktop-guide/net/wpf/get-started/media/create-app-visual-studio/vs-template-search-cs.png create mode 100644 dotnet-desktop-guide/net/wpf/get-started/media/create-app-visual-studio/vs-template-search-vb.png create mode 100644 dotnet-desktop-guide/net/wpf/get-started/media/create-app-visual-studio/vs-template-search.png create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/App.xaml create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/App.xaml.cs create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/AssemblyInfo.cs create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Final.xaml create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Final.xaml.cs create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep1.xaml create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep1.xaml.cs create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep2.xaml create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep2.xaml.cs create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep3.xaml create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep3.xaml.cs create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep4.xaml create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep4.xaml.cs create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls1.xaml create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls1.xaml.cs create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls2.xaml create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls2.xaml.cs create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls3.xaml create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls3.xaml.cs create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Names.csproj create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Start.xaml create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Start.xaml.cs create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Application.xaml create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Application.xaml.vb create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/AssemblyInfo.vb create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Final.xaml create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Final.xaml.vb create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/MoreControls3.xaml create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/MoreControls3.xaml.vb create mode 100644 dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Names.vbproj diff --git a/dotnet-desktop-guide/net/wpf/get-started/create-app-visual-studio.md b/dotnet-desktop-guide/net/wpf/get-started/create-app-visual-studio.md new file mode 100644 index 0000000..3b0c623 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/create-app-visual-studio.md @@ -0,0 +1,247 @@ +--- +title: "Create a new app with Visual Studio tutorial" +description: Follow this tutorial to learn how to create a new WPF app for .NET with Visual Studio 2019. +ms.date: 01/18/2021 +ms.topic: tutorial +dev_langs: + - "csharp" + - "vb" +--- + +# Tutorial: Create a new WPF app (WPF .NET) + +In this short tutorial, you'll learn how to create a new Windows Presentation Foundation (WPF) app with Visual Studio. Once the initial app has been generated, you'll learn how to add controls and how to handle events. By the end of this tutorial, you'll have a simple app that adds names to a list box. + +[!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)] + +In this tutorial, you learn how to: + +> [!div class="checklist"] +> +> - Create a new WPF app +> - Add controls to a form +> - Handle control events to provide app functionality +> - Run the app + +Here's a preview of the app you'll build while following this tutorial: + +:::image type="content" source="media/create-app-visual-studio/app-finished.png" alt-text="Finished sample app for WPF tutorial"::: + +## Prerequisites + +- [Visual Studio 2019 version 16.9 or later versions](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=inline+link&utm_content=download+vs2019+desktopguide+wpf) + - Select the [Visual Studio Desktop workload](/visualstudio/install/modify-visual-studio?view=vs-2019&preserve-view=true#modify-workloads) + - Select the [.NET 5 individual component](/visualstudio/install/modify-visual-studio?view=vs-2019&preserve-view=true#modify-individual-components) + +## Create a WPF app + +The first step to creating a new app is opening Visual Studio and generating the app from a template. + +01. Open Visual Studio. +01. Select **Create a new project**. + + :::image type="content" source="media/create-app-visual-studio/vs-create-new-project.png" alt-text="Create a new WPF project in Visual Studio 2019 for .NET"::: + +01. In the **Search for templates** box, type **wpf**, and then press Enter. +01. In the **code language** dropdown, choose **C#** or **Visual Basic**. +01. In the templates list, select **WPF Application** and then select **Next**. + + > [!IMPORTANT] + > Don't select the **WPF Application (.NET _Framework_)** template. + + :::image type="content" source="media/create-app-visual-studio/vs-template-search.png" alt-text="Search for the WPF template in Visual Studio 2019 for .NET"::: + +01. In the **Configure your new project** window, do the following: + + 01. In the **Project name** box, enter **Names**. + 01. Select the **Place solution and project in the same directory** check box. + 01. Optionally, choose a different **Location** to save your code. + 01. Select the **Next** button. + + :::image type="content" source="media/create-app-visual-studio/vs-config-new-project.png" alt-text="Configure new WPF project in Visual Studio 2019 for .NET"::: + +01. In the **Additional information** window, select **.NET 5.0 (Current)** for **Target Framework** and make sure that the **Run on .NET Framework** check box is cleared. Select the **Create** button. + + :::image type="content" source="media/create-app-visual-studio/vs-config-new-project-next.png" alt-text="Select target framework for new WPF project in Visual Studio 2019 for .NET"::: + +Once the app is generated, Visual Studio should open the XAML designer pane for the default window, _MainWindow_. If the designer isn't visible, double-click on the _MainWindow.xaml_ file in the **Solution Explorer** pane to open the designer. + +### Important parts of Visual Studio + +Support for WPF in Visual Studio has five important components that you'll interact with as you create an app: + +:::image type="content" source="media/create-app-visual-studio/vs-main-window.png" alt-text="The important components of Visual Studio you should know when creating a WPF project for .NET"::: + +01. Solution Explorer + + All of your project files, code, windows, resources, will appear in this pane. + +02. Properties + + This pane shows property settings you can configure based on the item selected. For example, if you select an item from **Solution Explorer**, you'll see property settings related to the file. If you select an object in the **Designer**, you'll see settings for that item. + +03. Toolbox + + The toolbox contains all of the controls you can add to a form. To add a control to the current form, double-click a control or drag-and-drop the control. + +04. XAML designer + + This is the designer for a XAML document. It's interactive and you can drag-and-drop objects from the **Toolbox**. By selecting and moving items in the designer, you can visually compose the user interface (UI) for your app. + + When both the designer and editor are visible, changes to one is reflected in the other. When you select items in the designer, the **Properties** pane displays the properties and attributes about that object. + +05. XAML code editor + + This is the XAML code editor for a XAML document. The XAML code editor is a way to craft your UI by hand without a designer. The designer may infer the values of properties on a control when the control is added in the designer. The XAML code editor gives you a lot more control. + + When both the designer and editor are visible, changes to one is reflected in the other. As you navigate the text caret in the code editor, the **Properties** pane displays the properties and attributes about that object. + +## Examine the XAML + +When your project is opened, the XAML code editor is visible with a minimal amount of XAML code to display the window: + +```xaml + + + + + +``` + +Let's break down this XAML code to understand it better. XAML is simply XML that can be processed by the compilers that WPF uses. It describes the WPF UI and interacts with .NET code. To understand XAML, you should, at a minimum, be familiar with the basics of XML. + +The document root `` represents the type of object being described by the XAML file. There are eight attributes declared, and they generally belong to three categories: + +- Namespaces + + An XML namespace provides structure to the XML, determining what is or isn't allowed to be declared in the file. + + The main `xmlns` attribute imports the XML namespace for the entire file, and in this case, maps to the types declared by WPF. The other XML namespaces declare a prefix and import other types and objects for the XAML file. For example, the `xmlns:local` namespace declares the `local` prefix and maps to the objects declared by your project, the ones declared in the `Names` code namespace. + +- `x:Class` attribute + + This attribute maps the `` to the type defined by your code: the _MainWindow.xaml.cs_ or _MainWindow.xaml.vb_ file, which is the `Names.MainWindow` class. + +- `Title` attribute + + Any normal attribute declared on the XAML object sets a property of that object. In this case the `Title` attribute sets the `Window.Title` property. + +## Change the window + +First, let's run the project and see the default output. You'll see that a window that pops up, without any controls, and a title of **MainWindow**: + +:::image type="content" source="media/create-app-visual-studio/app-default.png" alt-text="A blank WPF app"::: + +For our example app, this window is too large, and the title bar isn't descriptive. Change the title and size of the window by changing the appropriate attributes in the XAML to the following values: + +:::code language="xaml" source="snippets/create-app-visual-studio/csharp/Start.xaml" highlight="8"::: + +## Prepare the layout + +WPF provides a powerful layout system with many different layout controls. Layout controls help place and size child controls, and can even do so automatically. The default layout control provided to you in this XAML is the `` control. + +The `Grid` control lets you define rows and columns, much like a table, and place controls within the bounds of a specific row and column combination. You can have any number of child controls or other layout controls added to the `Grid`. For example, you can place another `Grid` control in a specific row and column combination, and that new `Grid` can then define more rows and columns and have its own children. + +The `` control defines rows and columns in which your controls will be. A grid always has a single row and column declared, meaning, the grid by default is a single cell. That doesn't really give you much flexibility in placing controls. + +Before we add the new rows and columns, add a new attribute to the `` element: `Margin="10"`. This insets the grid from the window and makes it look a little nicer. + +Next, define two rows and two columns, dividing the grid into four cells: + +:::code language="xaml" source="snippets/create-app-visual-studio/csharp/LayoutStep2.xaml" highlight="9-21"::: + +Select the grid in either the XAML code editor or XAML designer, you'll see that the XAML designer shows each row and column: + +:::image type="content" source="media/create-app-visual-studio/vs-designer-grid-rows-columns.png" alt-text="A WPF app with the margin set on a grid"::: + +## Add the first control + +Now that the grid has been created, we can start adding controls to it. First, start with the label control. Create a new ` diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Final.xaml.cs b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Final.xaml.cs new file mode 100644 index 0000000..c59c854 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Final.xaml.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace Names +{ + /// + /// Interaction logic for Final.xaml + /// + public partial class Final : Window + { + public Final() + { + InitializeComponent(); + } + + // + private void ButtonAddName_Click(object sender, RoutedEventArgs e) + { + if (!string.IsNullOrWhiteSpace(txtName.Text) && !lstNames.Items.Contains(txtName.Text)) + lstNames.Items.Add(txtName.Text); + } + // + } +} diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep1.xaml b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep1.xaml new file mode 100644 index 0000000..bead9dd --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep1.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep1.xaml.cs b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep1.xaml.cs new file mode 100644 index 0000000..7fc70b3 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep1.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace Names +{ + /// + /// Interaction logic for MainWindow2.xaml + /// + public partial class LayoutStep1 : Window + { + public LayoutStep1() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep2.xaml b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep2.xaml new file mode 100644 index 0000000..d1e6930 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep2.xaml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep2.xaml.cs b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep2.xaml.cs new file mode 100644 index 0000000..089bc75 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep2.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace Names +{ + /// + /// Interaction logic for LayoutStep2.xaml + /// + public partial class LayoutStep2 : Window + { + public LayoutStep2() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep3.xaml b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep3.xaml new file mode 100644 index 0000000..64d3513 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep3.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep3.xaml.cs b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep3.xaml.cs new file mode 100644 index 0000000..5060178 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep3.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace Names +{ + /// + /// Interaction logic for LayoutStep3.xaml + /// + public partial class LayoutStep3 : Window + { + public LayoutStep3() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep4.xaml b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep4.xaml new file mode 100644 index 0000000..911de12 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep4.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep4.xaml.cs b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep4.xaml.cs new file mode 100644 index 0000000..3aa203a --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/LayoutStep4.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace Names +{ + /// + /// Interaction logic for LayoutSteps4.xaml + /// + public partial class LayoutStep4 : Window + { + public LayoutStep4() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls1.xaml b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls1.xaml new file mode 100644 index 0000000..279693f --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls1.xaml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls1.xaml.cs b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls1.xaml.cs new file mode 100644 index 0000000..fe7eec6 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls1.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace Names +{ + /// + /// Interaction logic for MoreControls1.xaml + /// + public partial class MoreControls1 : Window + { + public MoreControls1() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls2.xaml b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls2.xaml new file mode 100644 index 0000000..2b8cd99 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls2.xaml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls2.xaml.cs b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls2.xaml.cs new file mode 100644 index 0000000..8e4e236 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls2.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace Names +{ + /// + /// Interaction logic for MoreControls2.xaml + /// + public partial class MoreControls2 : Window + { + public MoreControls2() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls3.xaml b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls3.xaml new file mode 100644 index 0000000..f2b59c8 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls3.xaml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls3.xaml.cs b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls3.xaml.cs new file mode 100644 index 0000000..76bac89 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/MoreControls3.xaml.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace Names +{ + /// + /// Interaction logic for MoreControls3.xaml + /// + public partial class MoreControls3 : Window + { + public MoreControls3() + { + InitializeComponent(); + } + + // + private void ButtonAddName_Click(object sender, RoutedEventArgs e) + { + + } + // + } +} diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Names.csproj b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Names.csproj new file mode 100644 index 0000000..407932c --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Names.csproj @@ -0,0 +1,9 @@ + + + + WinExe + net5.0-windows + true + + + diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Start.xaml b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Start.xaml new file mode 100644 index 0000000..76de164 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Start.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Start.xaml.cs b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Start.xaml.cs new file mode 100644 index 0000000..ea262d6 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/csharp/Start.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Names +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Application.xaml b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Application.xaml new file mode 100644 index 0000000..1ea92df --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Application.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Application.xaml.vb b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Application.xaml.vb new file mode 100644 index 0000000..084cbe9 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Application.xaml.vb @@ -0,0 +1,6 @@ +Class Application + + ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException + ' can be handled in this file. + +End Class diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/AssemblyInfo.vb b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/AssemblyInfo.vb new file mode 100644 index 0000000..025ee72 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/AssemblyInfo.vb @@ -0,0 +1,11 @@ +Imports System.Windows + +'The ThemeInfo attribute describes where any theme specific and generic resource dictionaries can be found. +'1st parameter: where theme specific resource dictionaries are located +'(used if a resource is not found in the page, +' or application resource dictionaries) + +'2nd parameter: where the generic resource dictionary is located +'(used if a resource is not found in the page, +'app, and any theme specific resource dictionaries) + diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Final.xaml b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Final.xaml new file mode 100644 index 0000000..bdbf9f0 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Final.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Final.xaml.vb b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Final.xaml.vb new file mode 100644 index 0000000..77f9c9e --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Final.xaml.vb @@ -0,0 +1,9 @@ +Public Class Final + ' + Private Sub ButtonAddName_Click(sender As Object, e As RoutedEventArgs) + If Not String.IsNullOrWhiteSpace(txtName.Text) And Not lstNames.Items.Contains(txtName.Text) Then + lstNames.Items.Add(txtName.Text) + End If + End Sub + ' +End Class diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/MoreControls3.xaml b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/MoreControls3.xaml new file mode 100644 index 0000000..166206d --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/MoreControls3.xaml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/MoreControls3.xaml.vb b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/MoreControls3.xaml.vb new file mode 100644 index 0000000..958c873 --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/MoreControls3.xaml.vb @@ -0,0 +1,7 @@ +Public Class MoreControls3 + ' + Private Sub ButtonAddName_Click(sender As Object, e As RoutedEventArgs) + + End Sub + ' +End Class diff --git a/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Names.vbproj b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Names.vbproj new file mode 100644 index 0000000..e696e3f --- /dev/null +++ b/dotnet-desktop-guide/net/wpf/get-started/snippets/create-app-visual-studio/vb/Names.vbproj @@ -0,0 +1,22 @@ + + + + WinExe + net5.0-windows + Names + true + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/net/wpf/toc.yml b/dotnet-desktop-guide/net/wpf/toc.yml index fa9a9d5..d6d7ee9 100644 --- a/dotnet-desktop-guide/net/wpf/toc.yml +++ b/dotnet-desktop-guide/net/wpf/toc.yml @@ -6,7 +6,7 @@ items: - name: Overview href: overview/index.md - name: Create a WPF application - href: /visualstudio/get-started/csharp/tutorial-wpf?view=vs-2019 + href: get-started/create-app-visual-studio.md # - name: Create a control library # href: getting-started/how-to-create-control-library.md - name: Migration