根据我的经验,XLabs的PopupLayout有时会存在问题。但是有一个非常好的库可以创建复杂的弹出窗口:Rg.Plugins.Popup。唯一的问题是:UWP实现尚未完成(但即将发布)。
XLabs有一个弹出布局,您可以使用它来实现此功能。
var pop = new XLabs.Forms.Controls.PopupLayout();
// PatientSearch is a ContentView I was to display in the popup
var search = new PatientSearch(data, this);
search.WidthRequest = 600;
search.HeightRequest = 500;
search.BackgroundColor = new Color (1, 1, 1, 0.8);
pop.ShowPopup(search);
<AbsoluteLayout x:Name="rootLayout" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" >
<StackLayout x:Name="mainLayout" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">
<!-- Put your main contents-->
</StackLayout>
<ContentView x:Name="popupOverlay"
IsVisible="{Binding IsPopupVisible}"
BackgroundColor="#C0808080"
AbsoluteLayout.LayoutBounds="0,0,1,1"
AbsoluteLayout.LayoutFlags="All">
<StackLayout x:Name="popupContent"
VerticalOptions="Center"
HorizontalOptions="Center"
WidthRequest="200"
HeightRequest="200">
<Entry Placeholder="UserName"></Entry>
<Entry Placeholder="Password"></Entry>
</StackLayout>
</ContentView>
</AbsoluteLayout>
我通常使用的解决方案是创建一个包含所有表单的StackLayout
,并将其作为当前页面的子元素插入其中,例如:
PopupPage popUp; //This will be the layout of the form
Page : ContentPage {
var gird = new Gird();
popUp = PopupPage();
popUp.IsVisible = false;
var mainContainer = new StackLayout();
mainContainer.Children.Add(All you UI stuff..);
var btn = new Button();
btn.Clicked += OnButtonClicked;
grid.Children.Add(mainContainer,0,0);
grid.Children.Add(popUp,0,0);
}
为了显示弹出窗口,您需要操作IsVisible属性,例如:
void OnButtonClicked(){
//You can center the popup using Vertical options or whatever you need
//and to resize the pop up you can do different calculations like
//popUp.Width = ScreenWidth / 2 and popUp.Height = ScreenWidth / 2
popUp.IsVisile = true;
}