Creating a bottom sheet using .NET MAUI

Creating a bottom sheet using .NET MAUI

02 September 2022

.NET MAUI/Xamarin

Buy Me A Coffee

Hello!

In this article, we will talk about bottom sheets. Bottom sheets are surfaces containing supplementary content and are anchored to the bottom of the screen.

You may have already seen similar articles where the implementation is based on AbsoluteLayout or Grid. Those implementations work great. The purpose of this article is to propose a different implementation using native controls.

So let's start with creating a new .NET MAUI application.

For Android we'll use BottomSheetDialog. It is a base class for Dialogs styled as a bottom sheet.

Create a new class PageExtensions in Platforms\Android folder with the next content:

For iOS/MacCatalyst we'll use UISheetPresentationController. It is a presentation controller that manages the appearance and behavior of a sheet. It is available since iOS 15.
Create a new class PageExtensions in Platforms\iOS folder or Platforms\MacCatalyst folder respectively with the next content:

Apple implementation provides more customization for a bottom sheet like a different size, dimming the background, user interaction, etc.

To display the bottom sheet alert call it on any Page:

where GetMyBottomSheetContent returns any view that you want to display on the bottom sheet.

That's it. As a result, you should receive such app:

iOS BottomSheet

The full code can be found on GitHub.

Happy coding!

Buy Me A Coffee

Related:

Migrate the deprecated OnBackPressed function in .NET MAUI Android application

This article is devoted to the new API added in Android 13, that adds support to predictive back gestures.

Drag and Drop any content to a .NET MAUI application

The article demonstrates how to add drop functionality to easily move content from the operating system to the .NET MAUI application.

An unhandled error has occurred. Reload

🗙