在Xamarin.Forms中我需要创建一个弹出窗口,在弹出窗口中显示登录页面。
这是我使用xlab弹出控件的代码。
MainPage l = new MainPage();
Navigation.PushModalAsync(l);
PopupLayout popupLayout = new PopupLayout();
popupLayout.Content = l.Content;
ShowPopup(l);
MainPage
扩展ContentPage
,目前其工作正常用于登录屏幕,但我的要求是将其显示为弹出窗口。有人可以帮忙吗?或者还有其他方法吗?
答案 0 :(得分:3)
这是你如何做的
private async void ShowPopup()
{
//Create `ContentPage` with padding and transparent background
ContentPage loginPage = new ContentPage
{
BackgroundColor = Color.FromHex("#D9000000"),
Padding = new Thickness(20, 20, 20, 20)
};
// Create Children
//Create desired layout to be a content of your popup page.
var contentLayout = new StackLayout
{
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
Orientation = StackOrientation.Vertical,
Children =
{
// Add children
}
};
//set popup page content:
loginPage.Content = contentLayout;
//Show Popup
await Navigation.PushModalAsync(loginPage, false);
}
答案 1 :(得分:0)
@misho谢谢你的帮助
这是我最后的工作代码。但它不能称为弹出窗口。这可以实现我的目的。
private async void ShowPopup()
{
ContentPage detailsPage = new ContentPage
{
BackgroundColor = Color.Transparent,// Color.FromHex("#00F0F8FF"),
Padding = new Thickness(40, 40, 40, 40)
};
MainPage l = new MainPage();
detailsPage.Content = l.Content;
Button b = l.FindByName<Button>("btnClose");
b.Clicked += ((o2, e2) =>
{
this.Navigation.PopModalAsync();
});
await Navigation.PushModalAsync(detailsPage, false);
}