【问题标题】:Is it possible to add listview in custom dialogbox in xamarin是否可以在 xamarin 的自定义对话框中添加列表视图
【发布时间】:2017-03-03 13:27:36
【问题描述】:

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

我想在自定义对话框中添加列表视图。可能吗? 如果可以的话,请分享解决方案。

您可以在下图中看到示例

【问题讨论】:

    标签: android ios listview xamarin dialog


    【解决方案1】:

    我将我的基本页面创建为带有按钮的绝对布局。当我按下按钮时,我将绝对布局 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);
        }
    }
    

    这是你的弹出窗口

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

    【讨论】:

    • 是的,但我想在对话框中打开列表视图。它应该看起来像对话框。有没有可能
    • 更新了我的答案
    猜你喜欢
    • 2011-02-21
    • 1970-01-01
    • 2021-04-10
    • 2016-11-13
    • 2012-12-29
    • 1970-01-01
    • 1970-01-01
    • 2013-07-28
    • 1970-01-01
    相关资源
    最近更新 更多