### Install and configure JDK Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/cli/android-management.md Automate the JDK setup process, including downloading a compatible version, installing it, and configuring the JAVA_HOME environment variable and system path. ```dotnetcli maui android jdk install ``` -------------------------------- ### Run interactive Android setup Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/cli/android-management.md Use this command for a full interactive setup of the Android development environment, ideal for new developers. It installs and configures the JDK, Android SDK, platform packages, accepts licenses, and optionally creates an emulator. ```dotnetcli maui android install ``` -------------------------------- ### Install MAUI macOS Template Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/platform-backends/macos.md Installs the .NET MAUI macOS template for creating new projects. Use this for a quick setup. ```bash # Install the template dotnet new install Microsoft.Maui.Platforms.MacOS.Templates --prerelease # Create a new macOS MAUI app dotnet new maui-macos -n MyApp.MacOS cd MyApp.MacOS dotnet run ``` -------------------------------- ### Install .NET xcsync Preview Source: https://github.com/dotnet/docs-maui/blob/main/docs/macios/xcsync.md Installs the preview version of the .NET xcsync tool globally. Use this command for both Visual Studio Code and CLI installations. ```dotnetcli dotnet tool install dotnet-xcsync -g --prerelease --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json ``` -------------------------------- ### Install Appium and Platform Drivers Source: https://github.com/dotnet/docs-maui/blob/main/docs/deployment/ui-testing.md Install Appium and the necessary platform drivers using npm. Install only the drivers for the platforms you intend to test. ```bash # Install Appium npm install -g appium # Install platform drivers (install only the ones you need) appium driver install uiautomator2 # Android appium driver install xcuitest # iOS (macOS only) appium driver install mac2 # Mac Catalyst (macOS only) appium driver install windows # Windows ``` -------------------------------- ### Install WPF MAUI Template Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/platform-backends/windows-wpf.md Installs the experimental WPF MAUI template and creates a new WPF MAUI application. ```bash # Install the template dotnet new install Microsoft.Maui.Platforms.Windows.WPF.Templates --prerelease # Create a new WPF MAUI app dotnet new maui-wpf -n MyApp.WPF cd MyApp.WPF dotnet run ``` -------------------------------- ### Install Objective Sharpie Source: https://github.com/dotnet/docs-maui/blob/main/docs/ios/objective-sharpie/get-started.md Install Objective Sharpie as a global .NET tool. This command installs the latest version. ```bash dotnet tool install -g Sharpie.Bind.Tool ``` -------------------------------- ### Implement UpdateInstallation method Source: https://github.com/dotnet/docs-maui/blob/main/docs/data-cloud/push-notifications.md This method handles PUT requests to the 'installations' endpoint. It creates or updates a device installation and returns an appropriate HTTP status code. ```csharp [HttpPut] [Route("installations")] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.UnprocessableEntity)] public async Task UpdateInstallation( [Required] DeviceInstallation deviceInstallation) { var success = await _notificationService .CreateOrUpdateInstallationAsync(deviceInstallation, HttpContext.RequestAborted); if (!success) return new UnprocessableEntityResult(); return new OkResult(); } ``` -------------------------------- ### Install .NET MAUI Workload Source: https://github.com/dotnet/docs-maui/blob/main/docs/includes/install-create-macos.md Install the latest public build of .NET MAUI, including necessary platform SDKs, using the .NET CLI. Requires administrator privileges. ```zsh sudo dotnet workload install maui --source https://api.nuget.org/v3/index.json ``` -------------------------------- ### Install .NET MAUI CLI Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/index.md Installs the .NET MAUI CLI as a global tool. This tool is experimental and subject to change. ```dotnetcli dotnet tool install -g Microsoft.Maui.Cli --prerelease ``` -------------------------------- ### List Installed Workloads Source: https://github.com/dotnet/docs-maui/blob/main/docs/get-started/installation.md Run this command in the terminal to verify that the .NET MAUI SDK workloads are installed. ```dotnetcli dotnet workload list ``` -------------------------------- ### Install MAUI Workload on Windows Source: https://github.com/dotnet/docs-maui/blob/main/docs/get-started/installation.md Use this command in the terminal on Windows to install the MAUI workload. ```dotnetcli dotnet workload install maui ``` -------------------------------- ### Create or Update Device Installation Source: https://github.com/dotnet/docs-maui/blob/main/docs/data-cloud/push-notifications.md Creates or updates a device installation in Notification Hubs. Ensure the DeviceInstallation object contains valid InstallationId, Platform, and PushChannel. ```csharp public async Task CreateOrUpdateInstallationAsync(DeviceInstallation deviceInstallation, CancellationToken token) { if (string.IsNullOrWhiteSpace(deviceInstallation?.InstallationId) || string.IsNullOrWhiteSpace(deviceInstallation?.Platform) || string.IsNullOrWhiteSpace(deviceInstallation?.PushChannel)) return false; var installation = new Installation() { InstallationId = deviceInstallation.InstallationId, PushChannel = deviceInstallation.PushChannel, Tags = deviceInstallation.Tags }; if (_installationPlatform.TryGetValue(deviceInstallation.Platform, out var platform)) installation.Platform = platform; else return false; try { await _hub.CreateOrUpdateInstallationAsync(installation, token); } catch { return false; } return true; } ``` -------------------------------- ### Install .NET Upgrade Assistant CLI Source: https://github.com/dotnet/docs-maui/blob/main/docs/migration/upgrade-assistant.md Installs the .NET Upgrade Assistant globally. Use `--ignore-failed-sources` if you have configured additional NuGet feed sources. ```dotnetcli dotnet tool install -g upgrade-assistant ``` ```dotnetcli dotnet tool install -g --ignore-failed-sources upgrade-assistant ``` -------------------------------- ### Verify .NET SDK Installation Source: https://github.com/dotnet/docs-maui/blob/main/docs/get-started/installation.md Run this command in your terminal to check if the .NET SDK is installed and to see its version. ```dotnetcli dotnet --version ``` -------------------------------- ### List Installed Xcode Versions Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/cli/apple-management.md Use this command to discover all Xcode installations on your machine. The output includes version, build number, path, and selection status. ```dotnetcli maui apple xcode list ``` -------------------------------- ### Display a prompt with optional arguments Source: https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/pop-ups.md This example shows how to configure a prompt with a predefined initial value, a maximum length for the input, and a specific keyboard type. ```csharp string result = await DisplayPromptAsync("Question 2", "What's 5 + 5?", initialValue: "10", maxLength: 2, keyboard: Keyboard.Numeric); ``` -------------------------------- ### C# Equivalent for EmptyView Setup Source: https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/controls/carouselview/emptyview.md This C# code demonstrates how to programmatically set up a CarouselView with a custom ContentView as its EmptyView, mirroring the XAML example. ```csharp StackLayout stackLayout = new StackLayout(); stackLayout.Add(new Label { Text = "No results matched your filter.", ... } ); stackLayout.Add(new Label { Text = "Try a broader filter?", ... } ); SearchBar searchBar = new SearchBar { ... }; CarouselView carouselView = new CarouselView { EmptyView = new ContentView { Content = stackLayout } }; carouselView.SetBinding(ItemsView.ItemsSourceProperty, static (MonkeysViewModel vm) => vm.Monkeys); ``` -------------------------------- ### Full Project File Example with Material 3 Enabled Source: https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/material-design.md This is a complete .csproj file example demonstrating how to enable Material 3 design for Android in a .NET MAUI project. It includes necessary configurations for target frameworks, application metadata, and Material 3 support. ```xml net10.0-android;net10.0-ios;net10.0-maccatalyst $(TargetFrameworks);net10.0-windows10.0.19041.0 Exe MyMauiApp true true enable true MyMauiApp com.companyname.mymauiapp 1.0 1 15.0 15.0 21.0 10.0.17763.0 10.0.17763.0 ``` -------------------------------- ### Set Initial Tab with XAML Source: https://github.com/dotnet/docs-maui/blob/main/docs/fundamentals/shell/tabs.md Set the `CurrentItem` property in XAML to specify which tab should be selected when the Shell app starts. This example selects the 'Dogs' tab. ```xaml ``` -------------------------------- ### Display .NET Installation Information Source: https://github.com/dotnet/docs-maui/blob/main/docs/troubleshooting.md Use this command to view detailed information about all installed .NET versions, including SDKs and runtimes. This can help in identifying version conflicts or missing components. ```bash dotnet --info ``` -------------------------------- ### Move Command Example Source: https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/controls/shapes/path-markup-syntax.md The 'M' command sets the starting point for a new figure. Multiple points can follow 'M' to draw lines to each point sequentially. ```xaml M 10,10 ``` -------------------------------- ### Customize WebView Handler for Android Source: https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/controls/webview.md Forces all WebView controls to use a custom chrome client on Android. This method should be called when the app starts, for example, in the MauiProgram.CreateMauiApp method. ```csharp private static void CustomizeWebViewHandler() { #if ANDROID26_0_OR_GREATER Microsoft.Maui.Handlers.WebViewHandler.Mapper.ModifyMapping( nameof(Android.Webkit.WebView.WebChromeClient), (handler, view, args) => handler.PlatformView.SetWebChromeClient(new MyWebChromeClient(handler))); #endif } ``` -------------------------------- ### Create an Android emulator Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/cli/android-management.md Create a new Android emulator with default hardware settings. The command downloads the required system image if it's not already installed. ```dotnetcli maui android emulator create --name MyEmulator ``` -------------------------------- ### Set StrokeLineCap to Round in XAML Source: https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/controls/shapes/index.md Use the `StrokeLineCap` property to define the shape of the line's start and end points. This example sets it to `Round` for a line with rounded ends. ```xaml ``` -------------------------------- ### Display sdk-db help information Source: https://github.com/dotnet/docs-maui/blob/main/docs/ios/objective-sharpie/tools.md Use the -help option to display detailed help information for the sdk-db tool, including all available options. ```bash $ sharpie sdk-db -help ``` -------------------------------- ### Set Initial FlyoutItem Selection with XAML Source: https://github.com/dotnet/docs-maui/blob/main/docs/fundamentals/shell/flyout.md Use the `CurrentItem` property in XAML to specify which FlyoutItem should be selected when the application starts. This example binds the `CurrentItem` to a ShellContent object named 'aboutItem'. ```xaml ... ``` -------------------------------- ### C# for StackLayout Alignment Options Source: https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/layouts/stacklayout.md This C# code creates a StackLayout with Label children, programmatically setting their HorizontalOptions to Start, Center, End, and Fill to replicate the XAML alignment example. ```csharp public class AlignmentPage : ContentPage { public AlignmentPage() { Title = "Alignment demo"; StackLayout stackLayout = new StackLayout { Margin = new Thickness(20), Spacing = 6 }; stackLayout.Add(new Label { Text = "Start", BackgroundColor = Colors.Gray, HorizontalOptions = LayoutOptions.Start }); stackLayout.Add(new Label { Text = "Center", BackgroundColor = Colors.Gray, HorizontalOptions = LayoutOptions.Center }); stackLayout.Add(new Label { Text = "End", BackgroundColor = Colors.Gray, HorizontalOptions = LayoutOptions.End }); stackLayout.Add(new Label { Text = "Fill", BackgroundColor = Colors.Gray, HorizontalOptions = LayoutOptions.Fill }); Content = stackLayout; } } ``` -------------------------------- ### Define a Custom Easing Func Delegate Source: https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/includes/easing-functions-dotnet9.md Define a custom easing function using a Func delegate. This example creates an easing function that starts fast, slows down, reverses, and then accelerates quickly. ```csharp Func CustomEaseFunc = t => 9 * t * t * t - 13.5 * t * t + 5.5 * t; await image.TranslateTo(0, 200, 2000, CustomEaseFunc); ``` -------------------------------- ### Example Xcode Build Error Message Source: https://github.com/dotnet/docs-maui/blob/main/docs/troubleshooting.md This error message indicates that the .NET build tools cannot locate the specified SDK path for Xcode, often due to an outdated or incorrect Xcode installation. ```text xcodebuild: error: SDK "/Applications/Xcode_14.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" cannot be located. xcrun: error: sh -c '/Applications/Xcode_14.1.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode_14.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find dsymutil 2> /dev/null' failed with exit code 16384: (null) (errno=Invalid argument) xcrun: error: unable to find utility "dsymutil", not a developer tool or in PATH ``` -------------------------------- ### Display Bind Tool Help Source: https://github.com/dotnet/docs-maui/blob/main/docs/ios/objective-sharpie/tools.md Use the -help option with the 'bind' tool to display detailed help information and available options for creating bindings. ```bash sharpie bind -help ``` -------------------------------- ### Create .NET MAUI App with Sample Content Source: https://github.com/dotnet/docs-maui/blob/main/docs/whats-new/dotnet-9.md Use the .NET CLI to create a new .NET MAUI project that includes a pre-built todo application with Syncfusion controls. ```dotnetcli dotnet new maui --sample-content -n MyProject ``` -------------------------------- ### Example ADB Devices Output Source: https://github.com/dotnet/docs-maui/blob/main/docs/android/emulator/troubleshooting.md This output indicates that the emulator is successfully connected and recognized by the Android SDK's adb tool. If your emulator does not appear, troubleshoot SDK installation and emulator startup. ```console List of devices attached emulator-5554 device ``` -------------------------------- ### Access Android App Context and Activity Source: https://github.com/dotnet/docs-maui/blob/main/docs/migration/native-essentials.md Use Platform.AppContext to get the current Android Context. Platform.CurrentActivity provides the current Activity or null if not initialized. Ensure the app has started before accessing CurrentActivity. ```csharp var context = Platform.AppContext; // Current Activity or null if not initialized or not started. var activity = Platform.CurrentActivity; ``` -------------------------------- ### Create a new .NET MAUI project Source: https://github.com/dotnet/docs-maui/blob/main/docs/get-started/installation.md Use this command to create a new .NET MAUI project. This is the first step before using the `InstallAndroidDependencies` build target. ```dotnetcli dotnet new maui -n "MyMauiApp" ``` -------------------------------- ### Create a Diagonal Linear Gradient Source: https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/graphics/paint.md Use LinearGradientPaint to create a diagonal gradient with multiple colors and offsets. This example demonstrates setting start and end colors, points, and adding intermediate gradient stops. ```csharp LinearGradientPaint linearGradientPaint = new LinearGradientPaint { StartColor = Colors.Yellow, EndColor = Colors.Green, StartPoint = new Point(0, 0), EndPoint = new Point(1, 1) }; linearGradientPaint.AddOffset(0.25f, Colors.Red); linearGradientPaint.AddOffset(0.75f, Colors.Blue); RectF linearRectangle = new RectF(10, 10, 200, 100); canvas.SetFillPaint(linearGradientPaint, linearRectangle); canvas.SetShadow(new SizeF(10, 10), 10, Colors.Grey); canvas.FillRoundedRectangle(linearRectangle, 12); ``` -------------------------------- ### Monitor Gyroscope Sensor Source: https://github.com/dotnet/docs-maui/blob/main/docs/platform-integration/device/sensors.md Call Start() to begin monitoring the gyroscope. The ReadingChanged event is raised when gyroscope data changes. Call Stop() to cease monitoring. Ensure the necessary platform-specific setup is completed. ```csharp IGyroscope gyroscope; public SensorsPage() { InitializeComponent(); gyroscope = Gyroscope.Default; } protected override void OnHandlerChangedTo(IView view) { base.OnHandlerChangedTo(view); if (gyroscope != null) { gyroscope.ReadingChanged += OnReadingChanged; } } protected override void OnHandlerDetachingFrom(IView view) { base.OnHandlerDetachingFrom(view); if (gyroscope != null && gyroscope.IsMonitoring) { Gyroscope.Stop(); } if (gyroscope != null) { gyroscope.ReadingChanged -= OnReadingChanged; } } void OnReadingChanged(object sender, GyroscopeChangedEventArgs e) { // Update UI Debug.WriteLine($"Reading: X:{e.Reading.AngularVelocity.X}, Y:{e.Reading.AngularVelocity.Y}, Z:{e.Reading.AngularVelocity.Z}"); } async void OnCounterClicked(object sender, EventArgs e) { if (gyroscope.IsMonitoring) { gyroscope.Stop(); // Update UI return; } // Turn on the gyroscope updates gyroscope.Start(); // Update UI } ``` -------------------------------- ### Publish Android App with Signing Details Source: https://github.com/dotnet/docs-maui/blob/main/docs/android/deployment/publish-cli.md Use this command to publish and sign your Android application. Ensure you have your keystore file and alias, and provide the necessary passwords. ```bash dotnet publish -f net8.0-android -c Release -p:AndroidKeyStore=true -p:AndroidSigningKeyStore=myapp.keystore -p:AndroidSigningKeyAlias=myapp -p:AndroidSigningKeyPass=mypassword -p:AndroidSigningStorePass=mypassword ``` -------------------------------- ### List installed Appium drivers Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/devflow/setup-apple.md Verify that the XCUITest driver is installed by listing all installed Appium drivers. ```bash appium driver list --installed ``` -------------------------------- ### Global Installation Source: https://github.com/dotnet/docs-maui/blob/main/docs/macios/xcsync.md Install the preview version of the .NET xcsync tool globally using the provided .NET CLI command. This command includes a specific NuGet package source for the preview release. ```APIDOC ## Global Installation Install the preview of .NET xcsync globally with the following command: ```dotnetcli dotnet tool install dotnet-xcsync -g --prerelease --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json ``` ``` -------------------------------- ### Run maui profile startup command Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/cli/profile.md Launches the app in a suspended state to capture a full startup trace. Supports various options for configuration. ```bash maui profile startup [options] ``` -------------------------------- ### Delete Device Installation by ID Source: https://github.com/dotnet/docs-maui/blob/main/docs/data-cloud/push-notifications.md Deletes a device installation from Notification Hubs using its installation ID. Returns false if the installationId is null or empty. ```csharp public async Task DeleteInstallationByIdAsync(string installationId, CancellationToken token) { if (string.IsNullOrWhiteSpace(installationId)) return false; try { await _hub.DeleteInstallationAsync(installationId, token); } catch { return false; } return true; } ``` -------------------------------- ### Display Sharpie Help Source: https://github.com/dotnet/docs-maui/blob/main/docs/ios/objective-sharpie/tools.md Use the -help option to display general help information and a list of available tools. ```bash sharpie -help ``` -------------------------------- ### Build and sign a .NET MAUI app Source: https://github.com/dotnet/docs-maui/blob/main/docs/android/deployment/publish-cli.md Use this command to build and sign your app with a specified keystore. Ensure all placeholder values like {filename}, {keyname}, and {password} are replaced with your actual keystore details. ```console dotnet publish -f net8.0-android -c Release -p:AndroidKeyStore=true -p:AndroidSigningKeyStore={filename}.keystore -p:AndroidSigningKeyAlias={keyname} -p:AndroidSigningKeyPass={password} -p:AndroidSigningStorePass={password} ``` -------------------------------- ### Scroll item to start of view Source: https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/controls/carouselview/scrolling.md Scrolls the item to the start of the view. ```csharp carouselView.ScrollTo(monkey, position: ScrollToPosition.Start); ``` -------------------------------- ### Install a specific Android SDK package Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/cli/android-management.md Install a specific Android SDK component using its package identifier. You can install multiple packages by running the command for each or by specifying multiple names if supported. ```dotnetcli maui android sdk install "platforms;android-35" ``` -------------------------------- ### Launch maui profile manual Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/cli/profile.md Use this command to start a .NET MAUI app in a non-suspended state, preparing it for manual profiling. Supports Android and iOS simulators only. ```bash maui profile manual [options] ``` -------------------------------- ### Start an iOS Simulator by Name Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/cli/apple-management.md Boots a specific iOS simulator using its name. The simulator launches in the background, allowing continued terminal use. ```dotnetcli maui apple simulator start "iPhone 17 Pro" ``` -------------------------------- ### Check FastFollow Asset Pack Installation Status Source: https://github.com/dotnet/docs-maui/blob/main/docs/android/asset-packs.md Use the `AssetPackManager` from the `Xamarin.Google.Android.Play.Asset.Delivery` NuGet package to check if a `FastFollow` asset pack is installed. If `AssetsPath()` returns null, the pack is not yet installed. ```csharp using Xamarin.Google.Android.Play.Core.AssetPacks; var assetPackManager = AssetPackManagerFactory.GetInstance(this); AssetPackLocation assetPackPath = assetPackManager.GetPackLocation("myfastfollowpack"); string assetsFolderPath = assetPackPath?.AssetsPath() ?? null; if (assetsFolderPath is null) { // FastFollow asset pack isn't installed. } ``` -------------------------------- ### List All Simulator Runtimes Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/cli/apple-management.md View all installed simulator runtimes on your machine. This command lists the name, platform, version, availability, and bundling status of each runtime. ```dotnetcli maui apple runtime list ``` -------------------------------- ### DropGestureRecognizer XAML Example Source: https://github.com/dotnet/docs-maui/blob/main/docs/fundamentals/gestures/drag-and-drop.md A XAML example demonstrating how to attach a DropGestureRecognizer to an Image control. ```APIDOC ## DELETE /api/users/{userId} ### Description Deletes a specific user. ### Method DELETE ### Endpoint /api/users/{userId} ### Parameters #### Path Parameters - **userId** (string) - Required - The unique identifier of the user to delete. ### Response #### Success Response (204) - No content is returned upon successful deletion. #### Response Example (No content) ``` -------------------------------- ### List available and installed Android SDK packages Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/cli/android-management.md View available and installed Android SDK packages to manage your development environment. The output displays package details including installed versions and available updates. ```dotnetcli maui android sdk list ``` -------------------------------- ### Install Android Emulator and System Images Source: https://github.com/dotnet/docs-maui/blob/main/docs/get-started/installation.md Use the `sdkmanager` command to download and install the Android emulator and a system image. The specific system image command varies between Windows and macOS, and between Apple Silicon and Intel Macs. ```bash sdkmanager --install emulator sdkmanager --install "system-images;android-35;google_apis;x86_64" ``` ```bash ./sdkmanager --install emulator ./sdkmanager --install "system-images;android-35;google_apis;arm64-v8a" ``` -------------------------------- ### Install Appium globally Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/devflow/setup-apple.md Install Appium globally using npm. This is required to run Appium. ```bash npm install -g appium ``` -------------------------------- ### Install MAUI Linux GTK4 Template Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/platform-backends/linux-gtk4.md Installs the .NET MAUI Linux GTK4 template for creating new projects. Use the --prerelease flag for the latest pre-release version. ```bash # Install the template dotnet new install Microsoft.Maui.Platforms.Linux.Gtk4.Templates --prerelease # Create a new Linux MAUI app dotnet new maui-linux-gtk4 -n MyApp.Linux cd MyApp.Linux dotnet run ``` -------------------------------- ### Get Long Press Gesture Position Source: https://github.com/dotnet/docs-maui/blob/main/docs/fundamentals/gestures/long-press.md Call the GetPosition method on LongPressedEventArgs or LongPressingEventArgs to retrieve the gesture's coordinates. Pass null to get the position within the window, or an Element to get the position relative to that element. ```csharp void OnLongPressed(object sender, LongPressedEventArgs e) { // Position inside the window Point? windowPosition = e.GetPosition(null); // Position relative to an Image Point? relativeToImagePosition = e.GetPosition(image); // Position relative to the container view Point? relativeToContainerPosition = e.GetPosition((View)sender); } ``` -------------------------------- ### Install Windows WPF MAUI Template Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/platform-backends/index.md Installs the prerelease template for creating .NET MAUI applications targeting Windows using WPF. Use this to scaffold a new Windows WPF MAUI project. ```bash dotnet new install Microsoft.Maui.Platforms.Windows.WPF.Templates --prerelease dotnet new maui-wpf -n MyApp.WPF ``` -------------------------------- ### Create an agent with a RAG context provider Source: https://github.com/dotnet/docs-maui/blob/main/docs/ai/agent-framework.md Implement an agent that uses a context provider to retrieve relevant data at runtime, injecting it into the agent's prompt for grounding information. This example uses a text-search provider for landmark data. ```csharp using Microsoft.Agents.AI; using Microsoft.Agents.AI.Hosting; using Microsoft.Extensions.AI; builder.AddAIAgent("researcher-agent", (sp, name) => { var chatClient = sp.GetRequiredKeyedService("local-model"); // Create a text-search provider that retrieves landmark data var searchProvider = CreateLandmarkSearchProvider(sp); return chatClient.AsAIAgent( new ChatClientAgentOptions { Name = name, ChatOptions = new ChatOptions { Instructions = """ Select the best matching destination from the provided candidates. Return detailed information that will help plan a day-by-day itinerary. "", }, AIContextProviders = [searchProvider], }, loggerFactory: sp.GetService()); }); ``` -------------------------------- ### Install MAUI-Android Workload on Linux Source: https://github.com/dotnet/docs-maui/blob/main/docs/get-started/installation.md Use this command in the terminal on Linux to install the MAUI Android workload. ```dotnetcli dotnet workload install maui-android ``` -------------------------------- ### Install ios-webkit-debug-proxy Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/devflow/setup-apple.md Install ios-webkit-debug-proxy using Homebrew. This is required for WebView debugging on physical iOS devices. ```bash brew install ios-webkit-debug-proxy ``` -------------------------------- ### Instantiate TodoItemDatabase Directly Source: https://github.com/dotnet/docs-maui/blob/main/docs/data-cloud/database-sqlite.md Shows how to create a new instance of the `TodoItemDatabase` directly within the `TodoItemPage` constructor, bypassing dependency injection. ```csharp TodoItemDatabase database; public TodoItemPage() { InitializeComponent(); database = new TodoItemDatabase(); } ``` -------------------------------- ### Programmatically Start Appium Local Server Source: https://github.com/dotnet/docs-maui/blob/main/docs/deployment/ui-testing.md This helper class allows for starting and stopping the Appium server as part of the test run, making the test suite self-contained. It configures the host and port for the server. ```csharp using OpenQA.Selenium.Appium.Service; namespace UITests; public static class AppiumServerHelper { private static AppiumLocalService? _appiumLocalService; public const string DefaultHostAddress = "127.0.0.1"; public const int DefaultHostPort = 4723; public static void StartAppiumLocalServer( string host = DefaultHostAddress, int port = DefaultHostPort) { if (_appiumLocalService is not null) return; var builder = new AppiumServiceBuilder() .WithIPAddress(host) .UsingPort(port); _appiumLocalService = builder.Build(); _appiumLocalService.Start(); } public static void DisposeAppiumLocalServer() { _appiumLocalService?.Dispose(); } } ``` -------------------------------- ### Install Appium XCUITest driver Source: https://github.com/dotnet/docs-maui/blob/main/docs/developer-tools/devflow/setup-apple.md Install the Appium XCUITest driver, which is necessary for testing on Apple platforms. ```bash appium driver install xcuitest ```