Skip to content

Commit 106a65b

Browse files
committed
Merged main into live
2 parents 93c7b65 + e5ebc76 commit 106a65b

File tree

4 files changed

+139
-102
lines changed

4 files changed

+139
-102
lines changed

hub/apps/develop/data-access/mysql-database.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
---
22
title: Use a MySQL database in a Windows app
33
description: Learn how to connect to a MySQL database from your Windows app, and test your connection using sample code.
4-
ms.date: 08/01/2024
4+
ms.date: 01/23/2025
5+
ms.collection: ce-skilling-ai-copilot
6+
ms.custom: copilot-scenario-highlight
57
ms.topic: how-to
68
keywords: windows, windows app sdk, MySQL, database, uwp, wpf, winforms, windows forms, winui
79
ms.localizationpriority: medium
@@ -21,6 +23,9 @@ This example can be used with any WPF, Windows Forms, WinUI 3, and UWP project t
2123

2224
This will allow you to programmatically access MySQL databases.
2325

26+
> [!NOTE]
27+
> [MySQL Connector/NET](https://dev.mysql.com/downloads/connector/net/) version 6.4.4 or later is required to use the `MySql.Data` package with Windows authentication.
28+
2429
## Test your connection using sample code
2530

2631
The following is an example of connecting to and reading from a remote MySQL database. Note that the server address and database name will need to be customized.
@@ -46,8 +51,19 @@ using (var mySqlCn = new MySqlConnection(M_str_sqlcon))
4651
> [!IMPORTANT]
4752
> In production applications, connection information should be stored securely in app configuration (see [**Adding Azure App Configuration by using Visual Studio Connected Services**](/visualstudio/azure/vs-azure-tools-connected-services-app-configuration)). Connection strings and other secrets should not be hard-coded.
4853
49-
> [!NOTE]
50-
> [MySQL Connector/NET](https://dev.mysql.com/downloads/connector/net/) version 6.4.4 or later is required to use the `MySql.Data` package with Windows authentication.
54+
## Building a connection string with GitHub Copilot
55+
56+
You can use GitHub Copilot to build the connection string for your MySQL database. You can customize the prompt to create a connection string per your requirements.
57+
58+
The following text shows an example prompt for Copilot Chat that generates a connection string similar to the one shown in the previous code snippet:
59+
60+
```copilot-prompt
61+
Show me how to create a MySQL connection string to a server named myServerAddress and a database called myDatabase. Use Windows authentication.
62+
```
63+
64+
GitHub Copilot is powered by AI, so surprises and mistakes are possible. For more information, see [Copilot FAQs](https://aka.ms/copilot-general-use-faqs).
65+
66+
Learn more about [GitHub Copilot in Visual Studio](/visualstudio/ide/visual-studio-github-copilot-install-and-states) and [GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/overview).
5167

5268
## Related content
5369

hub/apps/windows-dotnet-maui/index.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
22
title: Build Windows apps with .NET MAUI
33
description: Learn about .NET MAUI, benefits it provides to Windows developers, and how take your Windows apps cross-platform.
4-
ms.topic: article
5-
ms.date: 05/09/2024
4+
ms.topic: concept-article
5+
ms.date: 01/23/2025
66
keywords: windows win32, desktop development, Windows App SDK, .net maui
77
ms.localizationpriority: medium
8+
#Customer intent: As a Windows developer, I want to learn about .NET MAUI, the benefits it provides to Windows developers, and how to take my Windows apps cross-platform.
89
---
910

1011
# Build Windows apps with .NET MAUI
@@ -28,6 +29,9 @@ If you are planning to build a new app for Windows and want to target additional
2829
- **Native Controls**: .NET MAUI does not currently support using Windows App SDK controls. If you have existing controls from other Windows App SDK projects you intend to re-use or rely on 3rd Party or open source controls, you will need to find alternatives for .NET MAUI projects.
2930
- **Closer to Windows**: When writing .NET MAUI apps, it outputs a Windows App SDK app, but there is some translation to get from your code to the native Windows app. With Windows App SDK, you are eliminating that translation step and are less likely to encounter issues with styles, API compatibility, or layout.
3031

32+
> [!TIP]
33+
> Are you still deciding between .NET MAUI, WinUI, and other UI framework options? Check out the [Windows developer FAQ](../get-started/windows-developer-faq.yml) to learn about the different options for building native Windows apps. Then go watch the **Windows Dev Chat** episode on **Choosing your ideal dev platform**. The segment about [.NET MAUI](https://www.youtube.com/watch?v=4PJBJ8GICjM&list=PLI_J2v67C23bxTffW4XewbUEAOfSVZkrk&index=2&t=2193s) hosted by Beth Massi walks through examples and reasons for choosing .NET MAUI for your next app.
34+
3135
## .NET MAUI resources for Windows developers
3236

3337
### .NET MAUI documentation
@@ -45,7 +49,7 @@ This [one-day live stream](https://www.youtube.com/playlist?list=PLdo4fOcmZ0oWeP
4549
### .NET MAUI blog posts
4650

4751
- [5 .NET MAUI Features for Building Great Desktop Apps](https://devblogs.microsoft.com/dotnet/5-dotnet-maui-desktop-features/)
48-
- [Build Your Own Podcast App with .NET 7, Blazor, and .NET MAUI](https://devblogs.microsoft.com/dotnet/build-your-own-podcast-app-with-dotnet-blazor-and-dotnet-maui/)
52+
- [Build Your Own Podcast App with .NET, Blazor, and .NET MAUI](https://devblogs.microsoft.com/dotnet/build-your-own-podcast-app-with-dotnet-blazor-and-dotnet-maui/)
4953

5054
### GitHub
5155

@@ -82,12 +86,10 @@ If you haven't enabled development mode on your PC, see [Enable your device for
8286

8387
Check out a walk-through of [creating your first .NET MAUI app on Windows](./walkthrough-first-app.md).
8488

85-
## Related topics
89+
## Related content
8690

8791
[What is .NET MAUI](/dotnet/maui/what-is-maui)
8892

89-
[.NET MAUI supported platforms](/dotnet/maui/supported-platforms)
90-
91-
[WinUI overview](../winui/winui3/index.md)
93+
[Windows developer FAQ](../get-started/windows-developer-faq.yml)
9294

9395
[.NET MAUI Community Toolkit documentation](/dotnet/communitytoolkit/maui/)
Lines changed: 90 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
22
title: Build your first .NET MAUI app for Windows
33
description: Get hands-on with .NET MAUI by building your first cross-platform app on Windows.
4-
ms.topic: article
5-
ms.date: 08/15/2022
4+
ms.topic: how-to
5+
ms.date: 01/23/2025
66
keywords: windows win32, desktop development, Windows App SDK, .net maui
77
ms.localizationpriority: medium
8+
#Customer intent: As a Windows developer, I want to learn how to create and run my first .NET MAUI app for Windows in Visual Studio.
89
---
910

1011
# Build your first .NET MAUI app for Windows
@@ -23,29 +24,29 @@ If you haven't already set up your environment for .NET MAUI development, please
2324

2425
1. Launch Visual Studio, and in the start window click **Create a new project** to create a new project:
2526

26-
![Create a new project.](images/hello-maui-new-project.png)
27+
![Create a new project.](images/hello-maui-new-project.png)
2728

28-
2. In the **Create a new project** window, select **MAUI** in the All project types drop-down, select the **.NET MAUI App** template, and click the **Next** button:
29+
1. In the **Create a new project** window, select **MAUI** in the All project types drop-down, select the **.NET MAUI App** template, and click the **Next** button:
2930

30-
![.NET MAUI App template.](images/hello-maui-app-template.png)
31+
![.NET MAUI App template.](images/hello-maui-app-template.png)
3132

32-
3. In the **Configure your new project** window, give your project a name, choose a location for it, and click the **Next** button:
33+
1. In the **Configure your new project** window, give your project a name, choose a location for it, and click the **Next** button:
3334

34-
![Name the new project.](images/hello-maui-name-project.png)
35+
![Name the new project.](images/hello-maui-name-project.png)
3536

36-
4. In the **Additional information** window, click the **Create** button:
37+
1. In the **Additional information** window, click the **Create** button:
3738

38-
![Create new project.](images/hello-maui-addl-info-create.png)
39+
![Create new project.](images/hello-maui-addl-info-create.png)
3940

40-
5. Wait for the project to be created, and for its dependencies to be restored:
41+
1. Wait for the project to be created, and for its dependencies to be restored:
4142

42-
![Project is created.](images/hello-maui-project-created.png)
43+
![Project is created.](images/hello-maui-project-created.png)
4344

44-
6. In the Visual Studio toolbar, press the Windows Machine button to build and run the app.
45+
1. In the Visual Studio toolbar, press the Windows Machine button to build and run the app.
4546

46-
7. In the running app, press the **Click me** button several times and observe that the count of the number of button clicks is incremented:
47+
1. In the running app, press the **Click me** button several times and observe that the count of the number of button clicks is incremented:
4748

48-
![Run a MAUI app for the first time.](images/hello-maui-first-run-app.png)
49+
![Run a MAUI app for the first time.](images/hello-maui-first-run-app.png)
4950

5051
You just ran your first .NET MAUI app on Windows. In the next section, you'll learn how to add data binding and messaging features from the **MVVM Toolkit** to your app.
5152

@@ -59,116 +60,114 @@ Now that you have your first .NET MAUI app running on Windows, let's add some MV
5960

6061
1. Right-click the project in **Solution Explorer** and select **Manage NuGet Packages...** from the context menu.
6162

62-
2. In the **NuGet Package Manager** window, select the **Browse** tab and search for **CommunityToolkit.MVVM**:
63+
1. In the **NuGet Package Manager** window, select the **Browse** tab and search for **CommunityToolkit.MVVM**:
6364

64-
![CommunityToolkit.MVVM package.](images/hello-maui-mvvm-pkg.png)
65+
![CommunityToolkit.MVVM package.](images/hello-maui-mvvm-pkg.png)
6566

66-
3. Add the latest stable version of the **CommunityToolkit.MVVM** package (version 8.0.0 or later) to the project by clicking **Install**.
67+
1. Add the latest stable version of the **CommunityToolkit.MVVM** package (version 8.0.0 or later) to the project by clicking **Install**.
6768

68-
4. Close the **NuGet Package Manager** window after the new package has finished installing.
69+
1. Close the **NuGet Package Manager** window after the new package has finished installing.
6970

70-
5. Right-click the project again and select **Add | Class** from the context menu.
71+
1. Right-click the project again and select **Add | Class** from the context menu.
7172

72-
6. In the **Add New Item** window that appears, name the class `MainViewModel` and click **Add**:
73+
1. In the **Add New Item** window that appears, name the class `MainViewModel` and click **Add**:
7374

74-
![Add MainViewModel class.](images/hello-maui-add-vm.png)
75+
![Add MainViewModel class.](images/hello-maui-add-vm.png)
7576

76-
7. The `MainViewModel` class will be the data binding target for the `MainPage`. Update it to inherit from `ObservableObject` in the `CommunityToolkit.Mvvm.ComponentModel` namespace This will also require updating the class to be `public` and `partial`.
77+
1. The `MainViewModel` class will be the data binding target for the `MainPage`. Update it to inherit from `ObservableObject` in the `CommunityToolkit.Mvvm.ComponentModel` namespace This will also require updating the class to be `public` and `partial`.
7778

78-
8. The `MainViewModel` class will contain the following code. The `CountChangedMessage` record defines a message that is sent each time the Click me button is clicked, notifying the view of the change. The [ObservableProperty](/dotnet/communitytoolkit/mvvm/generators/observableproperty) and [RelayCommand](/dotnet/communitytoolkit/mvvm/generators/relaycommand) attributes added to the `message` and `IncrementCounter` members are source generators provided by the MVVM Toolkit to create the MVVM boilerplate code for `INotifyPropertyChanged` and `IRelayCommand` implementations. The `IncrementCounter` method's implementation contains the logic from `OnCounterClicked` in MainPage.xaml.cs, with a change to send a message with the new counter message. We will be removing that code-behind code later.
79+
1. The `MainViewModel` class will contain the following code. The `CountChangedMessage` record defines a message that is sent each time the Click me button is clicked, notifying the view of the change. The [ObservableProperty](/dotnet/communitytoolkit/mvvm/generators/observableproperty) and [RelayCommand](/dotnet/communitytoolkit/mvvm/generators/relaycommand) attributes added to the `message` and `IncrementCounter` members are source generators provided by the MVVM Toolkit to create the MVVM boilerplate code for `INotifyPropertyChanged` and `IRelayCommand` implementations. The `IncrementCounter` method's implementation contains the logic from `OnCounterClicked` in MainPage.xaml.cs, with a change to send a message with the new counter message. We will be removing that code-behind code later.
7980

80-
``` csharp
81-
using CommunityToolkit.Mvvm.ComponentModel;
82-
using CommunityToolkit.Mvvm.Input;
83-
using CommunityToolkit.Mvvm.Messaging;
84-
85-
namespace MauiOnWindows
86-
{
87-
public sealed record CountChangedMessage(string Text);
88-
89-
public partial class MainViewModel : ObservableObject
81+
``` csharp
82+
using CommunityToolkit.Mvvm.ComponentModel;
83+
using CommunityToolkit.Mvvm.Input;
84+
using CommunityToolkit.Mvvm.Messaging;
85+
86+
namespace MauiOnWindows
9087
{
91-
[ObservableProperty]
92-
private string message = "Click me";
93-
94-
private int count;
95-
96-
[RelayCommand]
97-
private void IncrementCounter()
88+
public sealed record CountChangedMessage(string Text);
89+
90+
public partial class MainViewModel : ObservableObject
9891
{
99-
count++;
100-
101-
if (count == 1)
102-
message = $"Clicked {count} time";
103-
else
104-
message = $"Clicked {count} times";
105-
106-
WeakReferenceMessenger.Default.Send(new CountChangedMessage(message));
92+
[ObservableProperty]
93+
private string message = "Click me";
94+
95+
private int count;
96+
97+
[RelayCommand]
98+
private void IncrementCounter()
99+
{
100+
count++;
101+
102+
// Pluralize the message if the count is greater than 1
103+
message = count == 1 ? $"Clicked {count} time" : $"Clicked {count} times";
104+
105+
WeakReferenceMessenger.Default.Send(new CountChangedMessage(message));
106+
}
107107
}
108108
}
109-
}
110-
```
109+
```
111110

112-
> [!NOTE]
113-
> You will need to update the namespace in the previous code to match the namespace in your project.
111+
> [!NOTE]
112+
> You will need to update the namespace in the previous code to match the namespace in your project.
114113

115-
9. Open the **MainPage.xaml.cs** file for editing and remove the `OnCounterClicked` method and the `count` field.
114+
1. Open the **MainPage.xaml.cs** file for editing and remove the `OnCounterClicked` method and the `count` field.
116115

117-
10. Add the following code to the `MainPage` constructor after the call to `InitializeComponenent()`. This code will receive the message sent by `IncrementCounter()` in the `MainViewModel` and will update the `CounterBtn.Text` property with the new message and announce the new text with the `SemanticScreenReader`:
116+
1. Add the following code to the `MainPage` constructor after the call to `InitializeComponent()`. This code will receive the message sent by `IncrementCounter()` in the `MainViewModel` and will update the `CounterBtn.Text` property with the new message and announce the new text with the `SemanticScreenReader`:
118117

119-
``` csharp
120-
WeakReferenceMessenger.Default.Register<CountChangedMessage>(this, (r, m) =>
121-
{
122-
CounterBtn.Text = m.Text;
123-
SemanticScreenReader.Announce(m.Text);
124-
});
125-
```
118+
``` csharp
119+
WeakReferenceMessenger.Default.Register<CountChangedMessage>(this, (r, m) =>
120+
{
121+
CounterBtn.Text = m.Text;
122+
SemanticScreenReader.Announce(m.Text);
123+
});
124+
```
126125

127-
11. You will also need to add a `using` statement to the class:
126+
1. You will also need to add a `using` statement to the class:
128127

129-
``` csharp
130-
using CommunityToolkit.Mvvm.Messaging;
131-
```
128+
``` csharp
129+
using CommunityToolkit.Mvvm.Messaging;
130+
```
132131

133-
12. In `MainPage.xaml`, add a namespace declaration to the `ContentPage` so the `MainViewModel` class can be found:
132+
1. In `MainPage.xaml`, add a namespace declaration to the `ContentPage` so the `MainViewModel` class can be found:
134133

135-
``` xaml
136-
xmlns:local="clr-namespace:MauiOnWindows"
137-
```
134+
``` xaml
135+
xmlns:local="clr-namespace:MauiOnWindows"
136+
```
138137

139-
13. Add `MainViewModel` as the `BindingContext` for the `ContentPage`:
138+
1. Add `MainViewModel` as the `BindingContext` for the `ContentPage`:
140139

141-
``` xaml
142-
<ContentPage.BindingContext>
143-
<local:MainViewModel/>
144-
</ContentPage.BindingContext>
145-
```
140+
``` xaml
141+
<ContentPage.BindingContext>
142+
<local:MainViewModel/>
143+
</ContentPage.BindingContext>
144+
```
146145

147-
14. Update the `Button` on `MainPage` to use a `Command` instead of handling the `Clicked` event. The command will bind to the `IncrementCounterCommand` public property that is generated by the MVVM Toolkit's source generators:
146+
1. Update the `Button` on `MainPage` to use a `Command` instead of handling the `Clicked` event. The command will bind to the `IncrementCounterCommand` public property that is generated by the MVVM Toolkit's source generators:
148147

149-
``` xaml
150-
<Button
151-
x:Name="CounterBtn"
152-
Text="Click me"
153-
SemanticProperties.Hint="Counts the number of times you click"
154-
Command="{Binding Path=IncrementCounterCommand}"
155-
HorizontalOptions="Center" />
156-
```
148+
``` xaml
149+
<Button
150+
x:Name="CounterBtn"
151+
Text="Click me"
152+
SemanticProperties.Hint="Counts the number of times you click"
153+
Command="{Binding Path=IncrementCounterCommand}"
154+
HorizontalOptions="Center" />
155+
```
157156

158-
15. Run the project again and observe that the counter is still incremented when you click the button:
157+
1. Run the project again and observe that the counter is still incremented when you click the button:
159158

160-
![Click me button clicked three times.](images/hello-maui-mvvm-clicked-3-times.png)
159+
![Click me button clicked three times.](images/hello-maui-mvvm-clicked-3-times.png)
161160

162-
16. While the project is running, try updating the "Hello, World!" message in the first Label to read "Hello, Windows!" in **MainPage.xaml**. Save the file and notice that [XAML Hot Reload](/dotnet/maui/xaml/hot-reload) updates the UI while the app is still running:
161+
1. While the project is running, try updating the "Hello, World!" message in the first Label to read "Hello, Windows!" in **MainPage.xaml**. Save the file and notice that [XAML Hot Reload](/dotnet/maui/xaml/hot-reload) updates the UI while the app is still running:
163162

164-
![Hello World updated to Hello Windows with XAML Hot Reload.](images/hello-maui-xaml-hot-reload-edited.png)
163+
![Hello World updated to Hello Windows with XAML Hot Reload.](images/hello-maui-xaml-hot-reload-edited.png)
165164

166165
## Next steps
167166

168-
Learn to build an app that displays [Microsoft Graph](/graph/) data for a user by leveraging the [Graph SDK](/graph/sdks/sdks-overview) in a [.NET MAUI for Windows tutorial](./tutorial-graph-api.md).
167+
Learn to build an app that displays [Microsoft Graph](/graph/) data for a user by leveraging the [Graph SDK](/graph/sdks/sdks-overview) in a [.NET MAUI for Windows tutorial](tutorial-graph-api.md).
169168

170-
## Related topics
169+
## Related content
171170

172171
[Resources for learning .NET MAUI](/dotnet/maui/get-started/resources)
173172

174-
[Using the Microsoft Graph API with .NET MAUI on Windows](./tutorial-graph-api.md)
173+
[Using the Microsoft Graph API with .NET MAUI on Windows](tutorial-graph-api.md)

0 commit comments

Comments
 (0)