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.
This specific example uses the ColorToHexRgbStringConverter
.
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...
}
}
At the top of your XAML file, add the following xmlns
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
In your Binding
assign Converter={converters:ColorToHexRgbStringConverter}
:
Text="{Binding Source={x:Reference ClickMeButton}, Path=BackgroundColor, Converter={toolkit:ColorToHexRgbStringConverter}}