Popover
allows you to display custom popovers (flyouts) anchored to any control. In order to use this control, you need to call the UseSimpleToolkit()
extension method in your MauiProgram.cs
file:
builder.UseSimpleToolkit();
Popover
and all related classes and methods can be found in the following namespace:
using SimpleToolkit.Core;
Or in the following XAML namespace:
xmlns:simpleCore="clr-namespace:SimpleToolkit.Core;assembly=SimpleToolkit.Core"
Simple popover anchored to a button can be defined as follows:
<Button
VerticalOptions="Center" HorizontalOptions="Center"
Clicked="ButtonClicked"
Text="Show popover"
Background="Orange">
<simpleCore:Popover.AttachedPopover>
<simpleCore:Popover>
<Border
Background="DarkOrange">
<Border.StrokeShape>
<RoundRectangle CornerRadius="6"/>
</Border.StrokeShape>
<VerticalStackLayout Padding="12,10" Spacing="10">
<simpleCore:Icon
Source="star.png"
TintColor="White"
VerticalOptions="Center"
HeightRequest="25" WidthRequest="25"/>
<Label
Text="Do you like this repo?"
TextColor="White"
FontAttributes="Bold"
VerticalOptions="Center"/>
</VerticalStackLayout>
</Border>
</simpleCore:Popover>
</simpleCore:Popover.AttachedPopover>
</Button>
Popover can be attached to a view using the AttachedPopover
attached property. Such a popover can be displayed or hidden (dismissed) by calling the ShowAttachedPopover()
and HideAttachedPopover()
extension methods on the view:
private void ButtonClicked(object sender, EventArgs e)
{
var button = sender as Button;
button.ShowAttachedPopover();
}
Output:
Android |
iOS |
---|---|
macOS |
Windows |
The Popover
class is inherited from the .NET MAUI Element
class. Popover
offers these essential properties and methods in addition to Element
s properties and methods:
Content
- the popover content of typeView
Show()
- shows the popover anchored to a view you pass as a parameterHide()
- hides the popover
Use of the methods mentioned above:
popover.Show(anchorView);
popover.Hide();
Popover can be attached to a view using the AttachedPopover
attached property. Such a popover can be displayed or hidden (dismissed) by calling the ShowAttachedPopover()
and HideAttachedPopover()
extension methods on the view:
button.ShowAttachedPopover();
button.HideAttachedPopover();
Using the UseDefaultStyling
boolean property, we can define whether the default platform-specific styling of the popover should be used. The default value is false
. If we set the property to true
, following results will be achieved:
Android |
iOS |
---|---|
macOS |
Windows |
On Android and Windows, popover alignment can be defined using the Alignment
property. This property accepts a value of the PopoverAlignment
enumeration type:
Center
- popover is centered to its anchorStart
- popover is aligned to the left edge of its anchorEnd
- popover is aligned to the right edge of its anchor
On iOS, permitted arrow directions can be defined using the PermittedArrowDirections
property. This property accepts flags of the PopoverArrowDirection
enumeration type:
Unknown
- the status of the arrow is currently unknownUp
- an arrow points upwardDown
- an arrow points downwardLeft
- an arrow points toward the leftRight
- an arrow points toward the rightAny
- an arrow points in any direction. This is the default value
We can, for example, allow the arrow to point only upward or downward:
popover.PermittedArrowDirections = PopoverArrowDirection.Up | PopoverArrowDirection.Down;
Show and hide animations of a popover can be disabled using the IsAnimated
boolean property. If we set the property to true
, animations are enabled, otherwise disabled.