How to show SnackBar and Toast in .NET MAUI
The .NET MAUI CommunityToolkit arrived as the successor to the Xamarin Community Toolkit, and this article, written around a new preview release, focuses on its two lightweight notification types.
After installing the CommunityToolkit.Maui package and calling UseMauiCommunityToolkit() in MauiProgram.cs, a toast is created with Toast.Make and shown with Show. Only one toast can be on screen at a time, and showing a second dismisses the first. A snackbar goes further: Snackbar.Make accepts an optional action and button text, a duration, visual options such as colors, corner radius and fonts, and an anchor element. There’s also a DisplaySnackbar extension for anchoring it to any VisualElement, along with Shown and Dismissed events and an IsShown property.
Vladislav also notes that both controls were rebuilt from scratch, so there are breaking changes if you’re coming from Xamarin Community Toolkit. It’s worth a read if you’re porting an app and want to replace its notification code.