此 .NET 多平台应用 UI (.NET MAUI) 特定于 iOS 平台,用于将模态页面显示为弹出窗口。 可以通过将 Page.ModalPopoverSourceView
可绑定属性设置为 View
,将 Page.ModalPopoverRect
可绑定属性设置为 Rectangle,以及将 Page.ModalPresentationStyle
可绑定属性设置为 UIModalPresentationStyle.Popover
来实现。 这可以在 C# 中使用 Fluent API 实现:
using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
...
public partial class PopoverPage : ContentPage
{
public PopoverPage(View modal, Rectangle rectangle)
{
InitializeComponent();
On<iOS>().SetModalPopoverView(modal);
On<iOS>().SetModalPopoverRect(rectangle);
On<iOS>().SetModalPresentationStyle(UIModalPresentationStyle.Popover);
}
}
Page.On<iOS>
方法指定该平台的特定功能将仅在 iOS 上运行。
Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific
命名空间中的 Page.SetModalPopoverView
方法用于设置弹出窗口的源视图。
Page.SetModalPopoverRect
方法用于设置视图中将是弹出控件来源的矩形区域。
Page.SetModalPresentationStyle
方法用于通过指定 UIModalPresentationStyle.Popover
枚举值将模式呈现样式设置为弹出窗口。
使用此特定于平台的功能将模式页显示为弹出窗口时,必须使用模式导航。
Page modalPage = new PopoverPage(originButton, Rectangle.Empty);
await Navigation.PushModalAsync(modalPage);
有关模式导航的详细信息,请参阅 执行模式导航。