HelloMauiToolkit icon indicating copy to clipboard operation
HelloMauiToolkit copied to clipboard

An iOS, Android, macOS + Windows app built using .NET MAUI, demonstrating how to use the .NET MAUI CommunityToolkit

.NET MAUI

HelloMauiToolkit

The .NET MAUI Community Toolkit is a collection of common elements for development with .NET MAUI that developers tend to replicate across multiple apps. It simplifies and demonstrates common developer tasks when building apps with .NET MAUI.

.NET MAUI Community Toolkit: Converters

This specific example uses the ColorToHexRgbStringConverter.

Add UseMauiCommunityToolkit()

In order to use the .NET MAUI Community Toolkit you need to call the extension method in your MauiProgram.cs file as follows:

using CommunityToolkit.Maui;

public static class MauiProgram
{
	public static MauiApp CreateMauiApp()
	{
		var builder = MauiApp.CreateBuilder();
		
		// Initialise the toolkit
		builder.UseMauiApp<App>().UseMauiCommunityToolkit();

		// the rest of your logic...
	}
}

Add XAML Namespace

At the top of your XAML file, add the following xmlns

xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"

Use ColorToHexRgbStringConverter

In your Binding assign Converter={converters:ColorToHexRgbStringConverter}:

Text="{Binding Source={x:Reference ClickMeButton}, Path=BackgroundColor, Converter={toolkit:ColorToHexRgbStringConverter}}