.NET MAUI Samples
repository·main·Indexed 25 days ago
https://github.com/dotnet/maui-samplesA collection of reference implementations and learning resources for .NET Multi-platform App UI (.NET MAUI). It includes samples for building cross-platform apps for Android, iOS, macOS, and Windows using C# and XAML, featuring implementations such as cross-platform age verification via IAgeSignalService and AI integration using IChatClient from Microsoft.Extensions.AI.
What's inside dotnet-maui-samples
- Word Puzzle is a .NET MAUI implementation of the classic 15-puzzle game. It demonstrates how to build a tile-based puzzle application using C# and XAML in .NET MAUI.
Overview of the Point of Sale Demo App
mainThe Point of Sale application is a .NET MAUI demo designed to showcase UI techniques for building adaptive desktop, tablet, and mobile applications from a single codebase. Key features demonstrated include:
- Customizing sidebar menus
- Implementing tab bars
- Using radio buttons
- Adapting UI to different device form factors (Desktop/Tablet vs. Mobile)
Note: This is a demonstration project and not a complete, production-ready application.
Overview of XAML markup extensions in .NET MAUI
mainXAML markup extensions in .NET MAUI enhance the flexibility of XAML by allowing element attributes to be set from various sources rather than being limited to static values. This sample provides demonstrations on how to consume existing markup extensions and how to implement custom ones.Overview of the Developer Balance sample app
mainThe Developer Balance sample app is a 'to do' application designed to demonstrate fundamental .NET MAUI development patterns and recommended community libraries. It serves as the inspiration for a new optional project template introduced in .NET 9.Overview of Age Signals Sample
mainThe Age Signals sample is a .NET MAUI application that demonstrates how to implement cross-platform age verification using platform-specific APIs. It provides a unified interface (
IAgeSignalService) to interact with:- Android: Google Play Age Signals (API 23+)
- iOS: Declared Age Range (iOS 26.0+)
- Windows: Age Consent API (Windows 11 Build 22000+)
Note: Mac Catalyst is not supported because the Apple DeclaredAgeRange framework is unavailable for Mac Catalyst targets.
Overview of Solitaire Encryption .NET MAUI Sample
mainThe Solitaire Encryption sample is a C# port of the encryption algorithm featured in Neal Stephenson's novel Cryptonomicon. It is implemented as a .NET MAUI application targeting iOS, Android, Windows, and macOS. The project also includes an xUnit test project containing tests derived from the author's website. The algorithm is based on a deck of cards, though this implementation abstracts that complexity within the UI.Overview of the BugSweeper sample
mainBugSweeper is a .NET MAUI implementation of a classic grid-based game. The game features a 9-by-9 grid of tiles where players must find and flag ten hidden bugs to win.
Gameplay Mechanics
- Starting the game: Double-tap any tile to begin. The first double-tap is guaranteed to be safe.
- Tile indicators: After the first move, numbers displayed on tiles indicate how many surrounding tiles contain bugs.
- Flagging bugs: Use a single tap on a tile to flag (or unflag) a suspected bug.
- Losing the game: Avoid double-tapping a tile that contains a bug.
Overview of the NuGetWithMSBuildFiles Sample Package
mainThis sample package demonstrates how to include MSBuild files within a .NET MAUI NuGet package. It specifically showcases how to package and distribute assets like fonts (e.g.,Font Awesome 6 Free-Regular-400.otf) so they are correctly integrated when consumed by a .NET MAUI application.Overview of the TipCalc sample
mainTipCalc is a .NET MAUI sample application that demonstrates how to build a tip calculator using XAML and data-binding. It allows users to input a food-and-drink subtotal and a post-tax total, then select a tip percentage. The application calculates the tip based on the subtotal and adds it to the post-tax total, rounding the final result to the nearest quarter.
Key technical features demonstrated:
- UI Definition: Uses XAML in
TipCalcPage.xaml. - Logic/Data Model: Calculations are encapsulated in a
TipCalcModelclass. - Data Binding: Utilizes data-binding and two custom value converters to manage data flow between the model and the UI.
- Cross-Platform Support: Builds for iOS, Android, Windows, and Mac Catalyst.
- UI Definition: Uses XAML in
Overview of BillingService Sample
mainThe
BillingServicesample demonstrates how to implement cross-platform in-app purchases in a .NET MAUI application using an MVVM architecture. It provides a unified interface to interact with platform-specific billing systems:- Android: Google Play Billing Client v7
- iOS & Mac Catalyst: Apple StoreKit 1
- Windows: Microsoft Store APIs
The sample covers product discovery, secure purchase flows, purchase restoration, and ownership verification.
Use Brushes to paint areas in .NET MAUI
mainIn .NET MAUI, you can use the
Brushclass to paint an area, such as the background of a control.Brushis an abstract class, and you use its derived classes to define different painting styles.Available brush types include:
SolidColorBrush: Paints an area with a single solid color.LinearGradientBrush: Paints an area using a linear gradient.RadialGradientBrush: Paints an area using a radial gradient.
Use the .NET MAUI RadioButton
mainTheRadioButtoncontrol in .NET MAUI allows users to select a single option from a predefined set. When multipleRadioButtoncontrols are grouped together, selecting one automatically deselects the previously selected button in that group. By default, eachRadioButtondisplays associated text.