是否可以在xamarin中的自定义对话框中添加listview

时间:2016-10-21 09:37:11

标签: android ios listview xamarin dialog

我正在使用具有android和IOS项目的便携式xamarin表单跨平台创建应用程序

我想在自定义对话框中添加listview。可能吗? 如果可能,请分享解决方案。

您可以在下图中看到示例

enter image description here

1 个答案:

答案 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" };
    }
}

enter image description here