当前位置: 首页 > news >正文

5.列表选择弹窗(BottomListPopup)

愿你出走半生,归来仍是少年! 

环境:.NET 7、MAUI 

        从底部弹出的列表选择弹窗。

1.布局

<?xml version="1.0" encoding="utf-8" ?>
<toolkit:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"x:Class="MauiLib.Utility.Controls.Popups.BottomListPopup"xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"x:Name="popup" xmlns:config="clr-namespace:MauiLib.Utility.Configs;assembly=MauiLib.Utility"Color="Transparent" VerticalOptions="End" > <VerticalStackLayout x:Name="outLyt"    BackgroundColor="Transparent"><Border  WidthRequest="1000"     BackgroundColor="White"   StrokeThickness="1"  StrokeShape="RoundRectangle 10,10,10,10"  HorizontalOptions="Center"><VerticalStackLayout    ><Label  x:Name="lbTitle"   Text="请选择任意一项" FontAttributes="Bold"  HorizontalOptions="Center" Padding="0,15,0,15" FontSize="18"/><Border Stroke="{Static config:ThemeConfig.SubTitle}" BackgroundColor="{Static config:ThemeConfig.SubTitle}"   StrokeThickness="0.2"  /><ListView    x:Name="lv"     RowHeight="35"   ItemSelected="lv_ItemSelected"   VerticalScrollBarVisibility="Never"><ListView.ItemTemplate><DataTemplate><ViewCell><Grid ><Grid.RowDefinitions><RowDefinition   /></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition  /></Grid.ColumnDefinitions><Label  Text="{Binding}" FontSize="14"  HorizontalTextAlignment="Center" VerticalTextAlignment="Center" TextColor="Black"/></Grid></ViewCell></DataTemplate></ListView.ItemTemplate></ListView></VerticalStackLayout></Border></VerticalStackLayout>
</toolkit:Popup>

2.代码 


public partial class BottomListPopup : CommunityToolkit.Maui.Views.Popup
{private Action<int, string> _itemClick;public string Title{set{lbTitle.Text = value;}}public BottomListPopup(List<string> items, Action<int, string> itemClick, int maxShowCount = 7){InitializeComponent();if (items == null || items.Count < 2){throw new ArgumentException("数据应至少两个!");}if (items.Distinct().Count()!=items.Count){throw new ArgumentException("数据不可存在重复项!");}lv.ItemsSource = items;_itemClick = itemClick;if (items.Count > maxShowCount){lv.HeightRequest = maxShowCount * 35;}else{lv.HeightRequest = items.Count * 35;}}private void lv_ItemSelected(object sender, SelectedItemChangedEventArgs e){_itemClick?.Invoke(e.SelectedItemIndex, e.SelectedItem.ToString());Close();}
}

3.使用

BottomListPopup popup = new BottomListPopup(new List<string>() { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", }, async (index, str) =>{await Toast.Make($"点击中第{index}项,数据为{str}").Show();});this.ShowPopup(popup);

4.效果

效果

http://www.lryc.cn/news/287877.html

相关文章:

  • (十三)Head first design patterns原型模式(c++)
  • Python基础之数据库操作
  • redis-发布缓存
  • Stata17安装教程
  • Java PDFBox 提取页数、PDF转图片
  • 【代码随想录14】104.二叉树的最大深度 111.二叉树的最小深度 222.完全二叉树的节点个数
  • AWS 专题学习 P10 (Databases、 Data Analytics)
  • 一键拥有你的GPT4
  • 幻兽帕鲁服务器数据备份
  • 【Digester解析XML文件的三种方式】
  • MATLAB curve fitting toolbox没有怎么办?
  • Linux之快速入门(CentOS 7)
  • Spring框架中的设计模式
  • Java数据结构与算法:邻接矩阵和邻接表
  • 【温故而知新】JavaScript类、类继承、静态方法
  • 小黑艰难的前端啃bug之路:内联元素之间的间隙问题
  • Ubuntu 申请 SSL证书并搭建邮件服务器
  • 视频监控方案设计:EasyCVR视频智能监管系统方案技术特点与应用
  • pyspark.sql.types 中的类型有哪些
  • 开源CRM客户管理系统-FeelCRM
  • Linux创建新分区挂载后普通用户没有读写权限
  • 清越 peropure·AI 国内版ChatGP新功能介绍
  • 力扣1027. 最长等差数列
  • GraphicsMagick 的 OpenCL 开发记录(二十三)
  • 通过Android Logcat分析firebase崩溃
  • 【AI大模型】WikiChat超越GPT-4:在模拟对话中事实准确率提升55%终极秘密
  • 【C语言刷题系列】水仙花数的打印及进阶
  • ICSpector:一款功能强大的微软开源工业PLC安全取证框架
  • HCIA——29HTTP、万维网、HTML、PPP、ICMP;万维网的工作过程;HTTP 的特点HTTP 的报文结构的选择、解答
  • 面试经典题---3.无重复字符的最长子串