Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hub/apps/develop/camera/camera-quickstart-winui3.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Add a call to this helper method to the **MainWindow** class constructor so that

:::code language="csharp" source="~/../snippets-windows/winappsdk/audio-video-camera/camera-winui/CS/CameraWinUI/MainWindow.xaml.cs" id="SnippetCameraWinUIConstructor":::

> [!TIP]
> If you're copying the sample into `MainWindow.xaml.cs`, also include the camera-related `using` directives used by the snippet source and add an empty `cbDeviceList_SelectionChanged` handler because the XAML wires that event. If you're validating the packaged sample from the command line, build it with `dotnet build -p:Platform=x64`.


## Initialize the MediaCapture object

Expand Down
1 change: 1 addition & 0 deletions hub/apps/develop/data-access/cosmos-db-data-access.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This article contains the steps required to enable working with a Cosmos DB data
This example can be used with any WPF, Windows Forms and WinUI project to connect your Windows app to a Cosmos DB database. Follow these steps to install the package and try out example code for some basic tasks.

1. Open the **Package Manager Console** (View -> Other Windows -> Package Manager Console). Use the command `Install-Package Microsoft.Azure.Cosmos` to install the NuGet package for the **Azure Cosmos DB for NoSQL client library for .NET**. This will allow you to programmatically access Cosmos DB databases.
1. In the **Package Manager Console**, run `Install-Package Newtonsoft.Json` before you build. Current `Microsoft.Azure.Cosmos` project targets in this tutorial also require an explicit Newtonsoft.Json package reference.
1. Build your project and make sure that the build was successful with no errors.

Next, you'll need to create a Cosmos DB instance in Azure. You can do this by following the steps in [Create a NoSQL database account in Azure Cosmos DB](/azure/cosmos-db/create-cosmosdb-resources-portal).
Expand Down
3 changes: 3 additions & 0 deletions hub/apps/develop/data-access/mongodb-database.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ This will allow you to programmatically access MongoDB databases.
The following sample code gets a collection from a remote MongoDB client, then adds a new document to that collection. Then it uses MongoDB APIs to retrieve the new size of the collection as well as the inserted document, and prints them out.

``` csharp
using MongoDB.Bson;
using MongoDB.Driver;

var client = new MongoClient("mongodb://10.xxx.xx.xxx:27017");
IMongoDatabase database = client.GetDatabase("foo");
IMongoCollection<BsonDocument> collection = database.GetCollection<BsonDocument>("bar");
Expand Down
4 changes: 4 additions & 0 deletions hub/apps/develop/data-access/mysql-database.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ This will allow you to programmatically access MySQL databases.
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.

``` csharp
using MySql.Data.MySqlClient;
using System.Data;
using System.Diagnostics;

const string M_str_sqlcon = "Server=myServerAddress;Database=myDataBase;IntegratedSecurity=yes;Uid=auth_windows;";
using (var mySqlCn = new MySqlConnection(M_str_sqlcon))
{
Expand Down
8 changes: 8 additions & 0 deletions hub/apps/develop/data-access/sql-server-database.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The snippets that appear in this guide are based on this [sample app](https://gi
To connect your app directly to a SQL Server database, your app can target any minimum version of Windows supported by Windows App SDK. You can find that information in the properties page of your project.

1. Open the **Package.appxmanifest** file of your Windows App SDK project in the manifest designer.
1. Install the SQL client package for current .NET project templates. In the **Package Manager Console**, run `Install-Package System.Data.SqlClient`.
1. In the **Capabilities** tab, select the **Enterprise Authentication** checkbox if you are using Windows Authentication for authenticating your SQL Server.

![Enterprise Authentication Capability](images/enterprise-authentication.png)
Expand Down Expand Up @@ -79,6 +80,8 @@ sealed partial class App : Application
We'll create a class that implements the [INotifyPropertyChanged](/dotnet/api/system.componentmodel.inotifypropertychanged) event so that we can bind attributes in our XAML UI to the properties in this class.

```csharp
using System.ComponentModel;

public class Product : INotifyPropertyChanged
{
public int ProductID { get; set; }
Expand All @@ -104,6 +107,11 @@ public class Product : INotifyPropertyChanged
In the **MainWindow.xaml.cs** file of the Windows App SDK project, create a method that gets products from the Northwind sample database, and then returns them as an [ObservableCollection](/dotnet/api/system.collections.objectmodel.observablecollection-1) collection of `Product` instances.

```csharp
using System;
using System.Collections.ObjectModel;
using System.Data.SqlClient;
using System.Diagnostics;

public ObservableCollection<Product> GetProducts(string connectionString)
{
const string GetProductsQuery = "select ProductID, ProductName, QuantityPerUnit," +
Expand Down
3 changes: 3 additions & 0 deletions hub/apps/develop/data-access/sqlite-data-access.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ Add the following `using` statements to the top of this file.

```csharp
using Microsoft.Data.Sqlite;
using System;
using System.Collections.Generic;
using System.IO;
using Windows.Storage;
```

### Initialize the SQLite database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ This article assumes that you know how to create a basic WinUI app. For instruct

Create a new **WinUI Blank App (Packaged)** project. Name it "MasterDetailsBinding".

> [!TIP]
> If you're validating the packaged WinUI project from the command line, build it with an explicit platform such as `dotnet build -p:Platform=x64`.

## Create the data model

Add a new class to your project, name it **ViewModel.cs**, and add this code to it. This class is your binding source class.
Expand Down
6 changes: 6 additions & 0 deletions hub/apps/develop/data-binding/data-binding-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ This topic assumes that you know how to create a basic WinUI app with Windows Ap

Create a new **WinUI Blank App (Packaged)** C# project. Name it "Quickstart".

> [!TIP]
> If you're validating the packaged WinUI project from the command line, build it with an explicit platform such as `dotnet build -p:Platform=x64`.

## Bind to a single item

Every binding consists of a binding target and a binding source. Typically, the target is a property of a control or other UI element, and the source is a property of a class instance (a data model, or a view model). This example shows how to bind a control to a single item. The target is the `Text` property of a `TextBlock`. The source is an instance of a simple class named `Recording` that represents an audio recording. Let's look at the class first.

Add a new class to your project, and name the class `Recording`.

``` csharp
using System;
using System.Collections.Generic;

namespace Quickstart
{
public class Recording
Expand Down
4 changes: 4 additions & 0 deletions hub/apps/develop/files/dotnet-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ WinUI apps can use [.NET APIs](/dotnet/) alongside WinRT and Win32 APIs to provi
- A packaged WinUI project
- Basic familiarity with C# and .NET development

> [!TIP]
> If you're validating a packaged WinUI project from the command line, build it with an explicit platform such as `dotnet build -p:Platform=x64`.

## What you'll learn

In this article, you'll learn how to:
Expand Down Expand Up @@ -149,6 +152,7 @@ This example shows how to use the [MemoryStream](/dotnet/api/system.io.memorystr
```csharp
using System.IO;
using System.Text;
using System.Threading.Tasks;
...
private async Task EncodeDecodeStringAsync(string inputData)
{
Expand Down
8 changes: 8 additions & 0 deletions hub/apps/develop/files/pickers-save-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Before you start, make sure you have:
- Basic familiarity with C# and XAML
- Understanding of async/await patterns in C#

> [!TIP]
> If you're validating a packaged WinUI project from the command line, build it with an explicit platform such as `dotnet build -p:Platform=x64`.

## Important APIs

The following APIs are used in this topic:
Expand All @@ -46,6 +49,8 @@ Use a [FileSavePicker](/windows/windows-app-sdk/api/winrt/microsoft.windows.stor

```csharp
using Microsoft.Windows.Storage.Pickers;
using System;
using System.Collections.Generic;
...
var savePicker = new FileSavePicker(this.AppWindow.Id)
{
Expand Down Expand Up @@ -124,8 +129,11 @@ Use the [FileTypeChoices](/windows/windows-app-sdk/api/winrt/microsoft.windows.s

2. Next, show the **FileSavePicker** and save to the picked file location. Display the file picker by calling [PickSaveFileAsync](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.filesavepicker.picksavefileasync). After the user specifies the name, file type, and location, and confirms to save the file, **PickSaveFileAsync** returns a lightweight [FilePickResult](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.pickfileresult) object that contains the path to the saved file and the filename. You can capture and process this file if you have read and write access to it.

If you want to show the cancellation message exactly as in the sample, add a placeholder `TextBlock` named `textBlock` to your XAML before wiring up the code-behind.

```csharp
using Microsoft.Windows.Storage.Pickers;
using System;
...
var savePicker = new FileSavePicker(this.AppWindow.Id);
var result = await savePicker.PickSaveFileAsync();
Expand Down
6 changes: 6 additions & 0 deletions hub/apps/develop/files/using-file-folder-pickers.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ The Windows App SDK [FileOpenPicker](/windows/windows-app-sdk/api/winrt/microsof

To learn about using a picker to save files, see [Save a file with a Windows App SDK picker](pickers-save-file.md).

> [!TIP]
> If you're validating a packaged WinUI picker sample from the command line, build it with an explicit platform such as `dotnet build -p:Platform=x64`.

## Important APIs

This article uses the following APIs:
Expand Down Expand Up @@ -53,6 +56,7 @@ For example, you might call the file picker in your app so that your user can op
The following code shows how to use the [FileOpenPicker](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.fileopenpicker) class to let the user pick a single file, such as a photo. The code sets properties on the picker to customize its appearance and behavior, and then shows the picker to the user by using the [PickSingleFileAsync](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.fileopenpicker.picksinglefileasync) method. If the user picks a file, the app reads the file's content and stores it in a variable.

```csharp
using System.Threading.Tasks;
using Microsoft.Windows.Storage.Pickers;

var openPicker = new FileOpenPicker(this.AppWindow.Id)
Expand Down Expand Up @@ -126,6 +130,7 @@ else
You can also let the user pick multiple files. The following code shows how to use the [FileOpenPicker](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.fileopenpicker) class to let the user pick multiple files, such as photos. The process is the same but the [PickMultipleFilesAsync](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.fileopenpicker.pickmultiplefilesasync) method returns a collection of file paths instead of a single path.

```csharp
using System.Threading.Tasks;
using Microsoft.Windows.Storage.Pickers;

var openPicker = new FileOpenPicker(this.AppWindow.Id);
Expand Down Expand Up @@ -174,6 +179,7 @@ else
To pick a folder by using the [FolderPicker](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.folderpicker) class, use the following code. This code creates a folder picker, shows it to the user by using the [PickSingleFolderAsync](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.folderpicker.picksinglefolderasync) method, and retrieves the selected folder's path in a [PickFolderResult](/windows/windows-app-sdk/api/winrt/microsoft.windows.storage.pickers.pickfolderresult) object. If the user picks a folder, the app retrieves the folder's path and stores it in a variable for later use.

```csharp
using System.Threading.Tasks;
using Microsoft.Windows.Storage.Pickers;

var folderPicker = new FolderPicker(this.AppWindow.Id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ For more information about managing workloads in Visual Studio, see [Modify Visu
2. In the **Create a new project** dialog, set the language filter to "C#" or "C++" and the platform filter to "WinUI", then select the "Blank App, Packaged (WinUI 3 in Desktop)" project template.
3. Name the new project "AppNotificationsExample".

> [!TIP]
> If you're validating this packaged WinUI project from the command line, build it with an explicit platform such as `dotnet build -p:Platform=x64`.

## Send a local app notification

In this section, you'll add a button to your app that sends a local app notification when clicked. The notification will include text content and an app logo image. You'll also add two read-only text boxes that will display the activation arguments when the user clicks on the notification.
Expand Down Expand Up @@ -190,7 +193,7 @@ When a user clicks on an app notification or a button within a notification, you
1. **Launch with UI** — The user clicks the notification body and your app should launch or come to the foreground, displaying relevant content.
2. **Background action** — The user clicks a button in the notification that triggers an action (such as sending a reply) without showing any app UI.

To support both scenarios, your app's activation flow should create the main window in `OnLaunched` but *not* activate it immediately. Instead, register the [AppNotificationManager.NotificationInvoked](/windows/windows-app-sdk/api/winrt/microsoft.windows.appnotifications.appnotificationmanager.notificationinvoked) event, call [AppNotificationManager.Register](/windows/windows-app-sdk/api/winrt/microsoft.windows.appnotifications.appnotificationmanager.register), and then check [AppInstance.GetActivatedEventArgs](/windows/windows-app-sdk/api/winrt/microsoft.windows.applifecycle.appinstance.getactivatedeventargs) to determine whether the app was launched from a notification or from a normal launch. If the launch was triggered by a notification, your code can inspect the notification arguments and decide whether to show the window or handle the action silently and exit.
To support both scenarios, your app's activation flow should create the main window in `OnLaunched` but *not* activate it immediately. Instead, register the [AppNotificationManager.NotificationInvoked](/windows/windows-app-sdk/api/winrt/microsoft.windows.appnotifications.appnotificationmanager.notificationinvoked) event, call [AppNotificationManager.Register](/windows/windows-app-sdk/api/winrt/microsoft.windows.appnotifications.appnotificationmanager.register), and then check [AppInstance.GetActivatedEventArgs](/windows/windows-app-sdk/api/winrt/microsoft.windows.applifecycle.appinstance.getactivatedeventargs) to determine whether this is a normal launch or a COM activation path that should wait for `NotificationInvoked`. Your code can then decide whether to show the window or handle the action silently and exit.

The `NotificationInvoked` event handles clicks that occur while the app is already running. When the app is not running, Windows launches the app via COM activation and the activation kind is reported as `Launch`, not `AppNotification`. The notification arguments are then delivered through the `NotificationInvoked` event.

Expand Down
11 changes: 9 additions & 2 deletions hub/apps/develop/security/windows-hello-auth-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ In this exercise, you start with the Windows Hello application built in the firs
// If the UserAccountList does not contain the sampleUser Initialize the sample users
// This is only needed as it in a Hand on Lab to demonstrate a user migrating
// In the real world user accounts would just be in a database
if (!_mockDatabaseUserAccountsList.Any(f = > f.Username.Equals("sampleUsername")))
{
if (!_mockDatabaseUserAccountsList.Any(f => f.Username.Equals("sampleUsername")))
{
//If the list is empty InitializeSampleUserAccountsAsync and return the list
await InitializeSampleUserAccountsAsync();
}
Expand Down Expand Up @@ -415,6 +415,9 @@ In this exercise, you start with the Windows Hello application built in the firs
- The **AuthService** class needs to create an instance of the **MockStore** class and provide access to the properties of the **MockStore** object.

```cs
using System;
using System.Collections.Generic;

namespace WindowsHelloLogin.AuthService
{
public class AuthService
Expand Down Expand Up @@ -906,6 +909,8 @@ In this exercise, you will be changing the client side views and helper classes
- In the **UserSelection** page class, only the code-behind needs to change, not the user interface. In UserSelection.xaml.cs, update the **UserSelection_Loaded** method and the **UserSelectionChanged** method to use the `UserAccount` class instead of the `Account` class. You will also need to get all users for this device through the **AuthService**.

```cs
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using WindowsHelloLogin.AuthService;

Expand Down Expand Up @@ -958,6 +963,8 @@ In this exercise, you will be changing the client side views and helper classes
- The **WindowsHelloRegister** page needs to have the code-behind file updated. The user interface does not need any changes. In WindowsHelloRegister.xaml.cs, remove the private `Account` variable at the top of the class, as it's no longer needed. Update the **RegisterButton_Click_Async** event handler to use the **AuthService**. This method will create a new **UserAccount** and then try and update its account details. If Windows Hello fails to create a key, the account will be removed as the registration process failed.

```cs
using System;

private async void RegisterButton_Click_Async(object sender, RoutedEventArgs e)
{
ErrorMessage.Text = "";
Expand Down
3 changes: 3 additions & 0 deletions hub/apps/develop/security/windows-hello-login.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ In order to build this project, you'll need some experience with C#, and XAML. Y
- Choose **WinUI Blank App (Packaged)** and name your application "WindowsHelloLogin".
- Build and Run the new application (F5), you should see a blank window shown on the screen. Close the application.

> [!TIP]
> If you're validating this packaged WinUI project from the command line, build it with an explicit platform such as `dotnet build -p:Platform=x64`.

![A screenshot of the new Windows Hello Login app running for the first time](images/windows-hello-login-1.png)

## Exercise 1: Login with Windows Hello
Expand Down
9 changes: 6 additions & 3 deletions hub/apps/develop/ui/navigation/navigate-between-two-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ To create a blank app in Visual Studio:
1. Select the **WinUI Blank App (Packaged)** project template, and click **Next**. That template creates a desktop app with a WinUI-based user interface.
1. In the **Project name** box, enter `BasicNavigation`, and click **Create**.
1. To run the program, choose **Debug** > **Start Debugging** from the menu, or press F5. Build and run your solution on your development computer to confirm that the app runs without errors. A blank page is displayed.

> [!TIP]
> If you're validating this packaged WinUI project from the command line, build it with an explicit platform such as `dotnet build -p:Platform=x64`.
1. To stop debugging and return to Visual Studio, exit the app, or click **Stop Debugging** from the menu.
1. Remove any example code that's included in the template from the `MainWindow.xaml` and `MainWindow` code-behind files.

Expand Down Expand Up @@ -441,13 +444,13 @@ using namespace winrt::Microsoft::UI::Xaml::Media::Animation;

// ...

void winrt::BasicNavigation::implementation::MainPage::HyperlinkButton_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e)
{
void winrt::BasicNavigation::implementation::Page2::HyperlinkButton_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e)
{
// Create the slide transition and set the transition effect to FromLeft.
SlideNavigationTransitionInfo slideEffect = SlideNavigationTransitionInfo();
slideEffect.Effect(SlideNavigationTransitionEffect(SlideNavigationTransitionEffect::FromLeft));
Frame().Navigate(winrt::xaml_typename<BasicNavigation::MainPage>(),
nullptr,
nullptr,
slideEffect);
}
```
Expand Down
Loading