.Net Maui 中的原生底层页!
** Show native BottomSheets with .NET MAUI!**
Check out the sample project to see the API in action!
iPhone
iPad
Phone
Tablet
Install the NuGet package:
dotnet add package Plugin.Maui.BottomSheetEnable the plugin in your MauiProgram.cs:
using Plugin.Maui.BottomSheet.Hosting;
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp()
.UseBottomSheet() // Add this line
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Build();Add the XAML namespace:
xmlns:bottomsheet="http://pluginmauibottomsheet.com"Create a simple bottom sheet:
Set peek height to view height (peek height changes dynamically as view height changes)
or
[!CAUTION] The peek height is calculated using MAUI's measurement behavior. Different platforms may return different heights for the same layout. You should not set a ScrollView as your peek view reference. Use the root of your ScrollView instead. This is especially true when using VerticalStackLayout and Grid with Star rows. To observe the differences, launch the Plugin.BottomSheet.Tests.Maui.Ui.Application test project and open the various peek BottomSheets
| Property | Type | Description |
|---|---|---|
IsModal |
bool |
Enable/disable interaction with content under BottomSheet |
IsCancelable |
bool |
Allow user to close via gestures or background click |
HasHandle |
bool |
Show/hide the drag handle |
ShowHeader |
bool |
Show/hide the header section |
IsOpen |
bool |
Control open/close state |
IsDraggable |
bool |
Enable/disable drag gestures (useful for drawing) |
States |
List |
Allowed states (Peek, Medium, Large) |
CurrentState |
BottomSheetState |
Current display state |
PeekHeight |
double |
Height when in peek state (iOS 16+) |
Padding |
double |
Internal padding |
BackgroundColor |
Color |
Background color |
CornerRadius |
float |
Top corner radius |
WindowBackgroundColor |
Color |
Window background (modal only) |
SizeMode |
BottomSheetSizeMode |
Represents a size mode for the bottom sheet where the height is adjusted dynamically to fit the content displayed within it or a fixed value based on the number of states it can display. |
| State | Description |
|---|---|
States |
Represents a size mode for the bottom sheet where the height is set to a fixed value based on the number of states it can display. This mode ensures the bottom sheet is fully expanded rather than dynamically adjusting its size to-fit content. |
FitToContent |
A size mode indicating that the bottom sheet dynamically adjusts its height to precisely fit the content it displays. In this mode, the bottom sheet wraps around its contents and does not occupy any more vertical space than necessary. |
[!CAUTION] Mode
FitToContentis not compatible with theStatesandCurrentStateproperty. Do not mix these two properties. Requires iOS 16+. On prior versions of iOS, the medium state will be used instead.
[!NOTE] On iOS and MacCatalyst, custom-detent presentations such as
FitToContentand peek-only sheets internally include a large detent sentinel so UIKit can keep non-modal sheets undimmed. If the user drags to that sentinel, the sheet automatically snaps back to the custom detent.
| State | Description |
|---|---|
Peek |
Fractional height (customizable) |
Medium |
Half screen height |
Large |
Full screen height |
| Property | Type | Description |
|---|---|---|
TitleText |
string |
Title text displayed in header |
TopLeftButton |
Button |
Custom button for top-left position |
TopRightButton |
Button |
Custom button for top-right position |
HeaderDataTemplate |
DataTemplate |
Custom view template (overrides other header properties) |
Content |
View |
Direct view content |
HeaderAppearance |
BottomSheetHeaderButtonAppearanceMode |
Controls which buttons are displayed |
ShowCloseButton |
bool |
Show built-in close button |
CloseButtonPosition |
CloseButtonPosition |
Position of close button (Left/Right) |
[!CAUTION] Be careful when using
Contentbecause the Content will be created even if the BottomSheet isn't open and this may have a negative performance impact.Contentshould only be used with navigation and not inBottomSheetsadded directly to aLayout.
| Property | Type | Description |
|---|---|---|
Content |
View |
Direct view content |
ContentTemplate |
DataTemplate |
Template for lazy loading |
[!CAUTION] Be careful when using
Contentbecause the Content will be created even if the BottomSheet isn't open and this may have a negative performance impact.Contentshould only be used with navigation and not inBottomSheetsadded directly to aLayout.
| Property | Type | Description |
|---|---|---|
HeaderStyle |
BottomSheetHeaderStyle |
Styling configuration for header elements |
| Property | Type | Description |
|---|---|---|
TitleTextColor |
Color |
Color of the title text |
TitleTextFontSize |
double |
Font size of the title text |
TitleTextFontAttributes |
FontAttributes |
Font attributes (Bold, Italic, None) |
TitleTextFontFamily |
string |
Font family name for title text |
TitleTextFontAutoScalingEnabled |
bool |
Enable automatic font scaling |
CloseButtonHeightRequest |
double |
Requested height for close button |
CloseButtonWidthRequest |
double |
Requested width for close button |
CloseButtonTintColor |
Color |
Tint color for close button icon |
暂无开放 Issues,或尚未同步最近议题。