diff --git a/hub/apps/develop/camera/camera-quickstart-winui3.md b/hub/apps/develop/camera/camera-quickstart-winui3.md index 2056ea4d3c..3188097f8d 100644 --- a/hub/apps/develop/camera/camera-quickstart-winui3.md +++ b/hub/apps/develop/camera/camera-quickstart-winui3.md @@ -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 diff --git a/hub/apps/develop/data-access/cosmos-db-data-access.md b/hub/apps/develop/data-access/cosmos-db-data-access.md index 7f319962d6..1c4e16ccd1 100644 --- a/hub/apps/develop/data-access/cosmos-db-data-access.md +++ b/hub/apps/develop/data-access/cosmos-db-data-access.md @@ -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). diff --git a/hub/apps/develop/data-access/mongodb-database.md b/hub/apps/develop/data-access/mongodb-database.md index d575a7afec..b99c9df4b1 100644 --- a/hub/apps/develop/data-access/mongodb-database.md +++ b/hub/apps/develop/data-access/mongodb-database.md @@ -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 collection = database.GetCollection("bar"); diff --git a/hub/apps/develop/data-access/mysql-database.md b/hub/apps/develop/data-access/mysql-database.md index 5a8b0fe560..d569908d57 100644 --- a/hub/apps/develop/data-access/mysql-database.md +++ b/hub/apps/develop/data-access/mysql-database.md @@ -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)) { diff --git a/hub/apps/develop/data-access/sql-server-database.md b/hub/apps/develop/data-access/sql-server-database.md index 11faa03d1e..994528a488 100644 --- a/hub/apps/develop/data-access/sql-server-database.md +++ b/hub/apps/develop/data-access/sql-server-database.md @@ -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) @@ -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; } @@ -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 GetProducts(string connectionString) { const string GetProductsQuery = "select ProductID, ProductName, QuantityPerUnit," + diff --git a/hub/apps/develop/data-access/sqlite-data-access.md b/hub/apps/develop/data-access/sqlite-data-access.md index fe662de6b0..1a148c70c6 100644 --- a/hub/apps/develop/data-access/sqlite-data-access.md +++ b/hub/apps/develop/data-access/sqlite-data-access.md @@ -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 diff --git a/hub/apps/develop/data-binding/bind-to-hierarchical-data-and-create-a-master-details-view.md b/hub/apps/develop/data-binding/bind-to-hierarchical-data-and-create-a-master-details-view.md index 7c83eee6cf..96c69f7e8e 100644 --- a/hub/apps/develop/data-binding/bind-to-hierarchical-data-and-create-a-master-details-view.md +++ b/hub/apps/develop/data-binding/bind-to-hierarchical-data-and-create-a-master-details-view.md @@ -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. diff --git a/hub/apps/develop/data-binding/data-binding-overview.md b/hub/apps/develop/data-binding/data-binding-overview.md index 0d3fc39e80..8c2bd399d5 100644 --- a/hub/apps/develop/data-binding/data-binding-overview.md +++ b/hub/apps/develop/data-binding/data-binding-overview.md @@ -23,6 +23,9 @@ 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. @@ -30,6 +33,9 @@ Every binding consists of a binding target and a binding source. Typically, the Add a new class to your project, and name the class `Recording`. ``` csharp +using System; +using System.Collections.Generic; + namespace Quickstart { public class Recording diff --git a/hub/apps/develop/files/dotnet-files.md b/hub/apps/develop/files/dotnet-files.md index 7b80c0f708..a6346f2557 100644 --- a/hub/apps/develop/files/dotnet-files.md +++ b/hub/apps/develop/files/dotnet-files.md @@ -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: @@ -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) { diff --git a/hub/apps/develop/files/pickers-save-file.md b/hub/apps/develop/files/pickers-save-file.md index 925857e73e..2d2f1de528 100644 --- a/hub/apps/develop/files/pickers-save-file.md +++ b/hub/apps/develop/files/pickers-save-file.md @@ -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: @@ -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) { @@ -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(); diff --git a/hub/apps/develop/files/using-file-folder-pickers.md b/hub/apps/develop/files/using-file-folder-pickers.md index b05e20c4cf..8928a100bb 100644 --- a/hub/apps/develop/files/using-file-folder-pickers.md +++ b/hub/apps/develop/files/using-file-folder-pickers.md @@ -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: @@ -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) @@ -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); @@ -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) diff --git a/hub/apps/develop/notifications/app-notifications/app-notifications-quickstart.md b/hub/apps/develop/notifications/app-notifications/app-notifications-quickstart.md index 33143cc812..93bab663dd 100644 --- a/hub/apps/develop/notifications/app-notifications/app-notifications-quickstart.md +++ b/hub/apps/develop/notifications/app-notifications/app-notifications-quickstart.md @@ -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. @@ -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. diff --git a/hub/apps/develop/security/windows-hello-auth-service.md b/hub/apps/develop/security/windows-hello-auth-service.md index fec464c6ac..19d654ebf4 100644 --- a/hub/apps/develop/security/windows-hello-auth-service.md +++ b/hub/apps/develop/security/windows-hello-auth-service.md @@ -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(); } @@ -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 @@ -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; @@ -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 = ""; diff --git a/hub/apps/develop/security/windows-hello-login.md b/hub/apps/develop/security/windows-hello-login.md index 0172d190e8..62a701f893 100644 --- a/hub/apps/develop/security/windows-hello-login.md +++ b/hub/apps/develop/security/windows-hello-login.md @@ -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 diff --git a/hub/apps/develop/ui/navigation/navigate-between-two-pages.md b/hub/apps/develop/ui/navigation/navigate-between-two-pages.md index a88087fa85..8f57378441 100644 --- a/hub/apps/develop/ui/navigation/navigate-between-two-pages.md +++ b/hub/apps/develop/ui/navigation/navigate-between-two-pages.md @@ -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. @@ -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(), - nullptr, + nullptr, slideEffect); } ``` diff --git a/hub/apps/develop/win2d/quick-start.md b/hub/apps/develop/win2d/quick-start.md index d2e2dcdad3..a659f7ca99 100644 --- a/hub/apps/develop/win2d/quick-start.md +++ b/hub/apps/develop/win2d/quick-start.md @@ -60,10 +60,13 @@ Before you continue, first ensure that the project's Architecture option is set 2. At the top of the C# file are various namespace definitions. Add the following namespaces: ```csharp -using Windows.UI; +using System; using System.Numerics; using Microsoft.Graphics.Canvas; using Microsoft.Graphics.Canvas.Effects; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Windows.UI; ``` 3. Next, you should see the following blank event handler which was inserted by AutoComplete: @@ -101,7 +104,7 @@ For more information, see [Avoiding memory leaks](./avoiding-memory-leaks.md). 3. Add a handler for the `Unloaded` event. Your XAML should look like this: ```XAML - @@ -245,13 +248,16 @@ args.DrawingSession.DrawImage(blur); ``` -Just like with **CanvasControl**, let AutoComplete create the `Draw` event handler for you. By default, Visual Studio will name this handler `canvas_Draw_1` because `canvas_Draw` already exists; here, we've renamed the method `canvas_AnimatedDraw` to make it clear that this is a different event. +Just like with **CanvasControl**, let AutoComplete create the `Draw` event handler for you. By default, Visual Studio will name this handler `canvas_Draw_1` because `canvas_Draw` already exists; here, we've renamed the method `canvas_DrawAnimated` to make it clear that this is a different event. In addition, you are also handling a new event, [CreateResources](https://microsoft.github.io/Win2D/WinUI2/html/E_Microsoft_Graphics_Canvas_UI_Xaml_CanvasAnimatedControl_CreateResources.htm). Once again, let AutoComplete create the handler. Now that your app will be redrawing at 60 frames per second, it is more efficient to create your Win2D visual resources once and reuse them with every frame. It is inefficient to create a `CanvasCommandList` and draw 300 elements into it 60 times per second when the content remains static. `CreateResources` is an event that is fired only when Win2D determines you need to recreate your visual resources, such as when the page is loaded. -3. Switch back to `MainPage.xaml.cs`. Find your `canvas_Draw` method which should look like this: +3. Switch back to `MainWindow.xaml.cs`. Find your `canvas_Draw` method which should look like this: + + > [!NOTE] + > The final WinUI 3 sample in this walkthrough stays in the `MainWindow.xaml` and `MainWindow.xaml.cs` files. If you created a page while experimenting, move the final animated sample code back into those two files so the XAML and code-behind stay aligned. ```csharp private void canvas_Draw( @@ -289,7 +295,7 @@ private void canvas_CreateResources( {} ``` -Paste (CTRL+V) your previously cut code into this method. Next, move the declaration of `GaussianBlurEffect` outside the method body so the variable becomes a member of the MainPage class. Your code should now look like the following: +Paste (CTRL+V) your previously cut code into this method. Next, move the declaration of `GaussianBlurEffect` outside the method body so the variable becomes a member of the MainWindow class. Your code should now look like the following: ```csharp GaussianBlurEffect blur; diff --git a/hub/apps/get-started/simple-photo-viewer-winui3.md b/hub/apps/get-started/simple-photo-viewer-winui3.md index 5ab3cd8cef..ef3ad434b2 100644 --- a/hub/apps/get-started/simple-photo-viewer-winui3.md +++ b/hub/apps/get-started/simple-photo-viewer-winui3.md @@ -28,6 +28,9 @@ To set up your development computer, see [Get started with WinUI](../get-started In Visual Studio, create your choice of a new C# or C++ project from the **WinUI Blank App (Packaged)** project template. Name the project *SimplePhotos*, and (so that your folder structure will match the one described in this tutorial) uncheck **Place solution and project in the same directory**. You can target the most recent release (not preview) of the client operating system. +> [!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`. + ## Step 3: Copy asset files The app that we'll be building carries image files around with it in the form of asset files; and those are the photos that it displays. In this section you'll add those assets to your project. But first you'll need to obtain a copy of the files. @@ -447,6 +450,7 @@ In this section we'll add a new property to the **MainWindow** class. The proper ```csharp ... + using System; using System.Threading.Tasks; using Windows.ApplicationModel; using Windows.Storage; diff --git a/hub/apps/how-tos/ai-build.md b/hub/apps/how-tos/ai-build.md index 68763c49fd..1cf5b38539 100644 --- a/hub/apps/how-tos/ai-build.md +++ b/hub/apps/how-tos/ai-build.md @@ -34,6 +34,9 @@ In this tutorial, you use GitHub Copilot in agent mode to build a complete WinUI Create a new WinUI 3 project: in Visual Studio, select **File** > **New** > **Project**, filter by **WinUI**, and choose the **WinUI Blank App (Packaged)** C# template. Name the project `NotesApp` and open it. +> [!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`. + ### Open Copilot agent mode and scaffold the structure Open the Copilot Chat panel in Visual Studio and switch to **agent mode**. Then enter: @@ -104,10 +107,11 @@ AppNotificationManager.Default.Show(notification); When you're ready to distribute or publish to the Microsoft Store, build a proper MSIX package: ```bash -winapp pack --output ./publish +dotnet build -p:Platform=x64 +winapp pack .\bin\x64\Debug\\win-x64 --manifest .\Package.appxmanifest --output .\publish\NotesApp.msix --generate-cert --executable NotesApp.exe ``` -This generates a signed MSIX package ready for sideloading or Store submission. Ask Copilot for help updating the package manifest: +Replace `` with your app's build output folder name (for example, `net10.0-windows10.0.26100.0`). This generates a signed MSIX package ready for sideloading or Store submission. Ask Copilot for help updating the package manifest: > *"Show me how to update the Package.appxmanifest to set the display name, description, and publisher for Store submission."* diff --git a/hub/apps/how-tos/ai-setup.md b/hub/apps/how-tos/ai-setup.md index 497b35396a..60122c7d83 100644 --- a/hub/apps/how-tos/ai-setup.md +++ b/hub/apps/how-tos/ai-setup.md @@ -57,7 +57,7 @@ Run this command in your project root (or any directory where you want Copilot t copilot plugin install winui3-development@awesome-copilot ``` -This copies agents, skills, and custom instructions into your project's `.github/` directory. Copilot automatically picks them up the next time you open the project. +This copies agents, skills, and custom instructions into your project's `.github/` directory. Copilot automatically picks them up the next time you open the project. After installation, run `copilot plugin list` and confirm that `winui3-development@awesome-copilot` appears in the installed plugins list. > [!TIP] > You can also browse and install Copilot plugins directly from VS Code using the [Awesome Copilot extension](https://marketplace.visualstudio.com/items?itemName=TimHeuer.awesome-copilot). diff --git a/hub/apps/winui/winui3/desktop-winui3-app-with-basic-interop.md b/hub/apps/winui/winui3/desktop-winui3-app-with-basic-interop.md index 91771e9609..6f98dc8843 100644 --- a/hub/apps/winui/winui3/desktop-winui3-app-with-basic-interop.md +++ b/hub/apps/winui/winui3/desktop-winui3-app-with-basic-interop.md @@ -16,6 +16,9 @@ In this topic, we step through how to build a basic **C# .NET** application with 1. [Start developing Windows apps](../../get-started/start-here.md) +> [!TIP] +> If you're validating either packaged WinUI sample in this walkthrough from the command line, build it with an explicit platform such as `dotnet build -p:Platform=x64`. + ## Basic managed C#/.NET app For this example, we'll specify the location and size of the app window, convert and scale it for the appropriate DPI, disable the window minimize and maximize buttons, and finally query the current process to show a list of the modules that are loaded into the current process. @@ -216,4 +219,4 @@ void MainWindow::customButton_Click(IInspectable const&, RoutedEventArgs const&) - [Windows App SDK](../../windows-app-sdk/index.md) - [Manage app windows](../../develop/ui-input/manage-app-windows.md) -- [Windows App SDK Samples](https://github.com/microsoft/WindowsAppSDK-Samples) \ No newline at end of file +- [Windows App SDK Samples](https://github.com/microsoft/WindowsAppSDK-Samples) diff --git a/hub/apps/winui/winui3/xaml-templated-controls-winui-3.md b/hub/apps/winui/winui3/xaml-templated-controls-winui-3.md index be11bccac9..5c9f2b7dc7 100644 --- a/hub/apps/winui/winui3/xaml-templated-controls-winui-3.md +++ b/hub/apps/winui/winui3/xaml-templated-controls-winui-3.md @@ -34,6 +34,9 @@ To create standalone WinUI components in C# for consumption from both C# and C++ Begin by creating a new project in Microsoft Visual Studio. In the **Create a new project** dialog, select the **WinUI Blank App (Packaged)** project template and select the appropriate language version. Set the project name to "BgLabelControlApp" so that the file names align with the code in the examples below. +> [!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`. + ::: zone pivot="lang-csharp" ![WinUI Blank App (Packaged) Project Template](images/new-project-packaged-winui3-desktop.png)