答案 0 :(得分:0)
我创建了我的基页作为Absolute Layout with button。当我按下按钮时,我将绝对布局PopUpListView推到顶部。这是代码。 在主页上
class LoginPage : ContentPage
{
Button btnLogin;
AbsoluteLayout layout;
public LoginPage()
{
layout = new AbsoluteLayout
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
};
BackgroundColor = Color.FromUint(0xFFDBDBDB);
btnLogin = new Button
{
HorizontalOptions = LayoutOptions.FillAndExpand,
Text = "Press me",
BackgroundColor = Color.FromUint(0xFF6E932D),
TextColor = Color.White,
};
btnLogin.Clicked += BtnLogin_Clicked;
layout.Children.Add(btnLogin, new Rectangle(0.5f, 0.1f, 0.25f, 0.25f), AbsoluteLayoutFlags.All);
Content = layout;
}
private void BtnLogin_Clicked(object sender, EventArgs e)
{
layout.Children.Add(new PopUpListView(), new Rectangle(0, 0, 1, 1), AbsoluteLayoutFlags.All);
}
}
这是你的Popoup
public class PopUpListView : AbsoluteLayout
{
public PopUpListView()
{
BackgroundColor = Color.FromRgba(0, 0, 0, 0.4);
var list = new MyListView();
Children.Add(list, new Rectangle(0.5f, 0.5f, 0.5f, 0.5f), AbsoluteLayoutFlags.All);
}
}
class MyListView : ListView
{
public MyListView()
{
BackgroundColor = Color.Black;
ItemsSource =new string[] {"1 choice", "2 choice", "3 choice" };
}
}