using System; using System.Collections.Generic; using HDL_ON.UI.CSS; using Shared; namespace HDL_ON.UI { public class ListCellDialog { /// /// 数据集合 /// Dictionary items = new Dictionary(); /// /// 当前选中目标 /// string curItem = ""; /// /// 回掉方法 /// Action fallbackAction; public ListCellDialog(Dictionary list,string curItem,Action fallbackAction) { items = list; this.curItem = curItem; this.fallbackAction = fallbackAction; } /// /// 加载在右边的弹窗 /// public void ShowRightDialog() { Dialog dialog = new Dialog(); FrameLayout dialogBodyView = new FrameLayout() { BackgroundColor = CSS_Color.DialogTransparentColor1, }; dialog.AddChidren(dialogBodyView); int itemCount = 1; var itemViewHeight = Application.GetRealHeight(73); switch(items.Count) { case 0: case 1: itemCount = 1; itemViewHeight = Application.GetRealHeight(73); break; case 2: itemCount = 2; itemViewHeight = Application.GetRealHeight(111); break; case 3: itemCount = 3; itemViewHeight = Application.GetRealHeight(155); break; case 4: itemCount = 4; itemViewHeight = Application.GetRealHeight(199); break; default: itemCount = 5; itemViewHeight = Application.GetRealHeight(243); break; } FrameLayout contentView; contentView = new FrameLayout() { X = Application.GetRealWidth(205), Y = Application.GetRealHeight(106), Width = Application.GetRealWidth(160), Height = itemViewHeight, BackgroundImagePath = "Public/ListCellbg/ListCellbg" + itemCount.ToString() + ".png", }; dialogBodyView.AddChidren(contentView); VerticalScrolViewLayout itemsView; itemsView = new VerticalScrolViewLayout() { X = Application.GetRealWidth(8), Y = Application.GetRealHeight(14), Width = Application.GetRealWidth(160), Height = Application.GetRealHeight(44 * itemCount), ScrollEnabled = itemCount == 5 }; contentView.AddChidren(itemsView); bool isFrist = true; foreach (var item in items) { if (isFrist) { isFrist = false; } else { itemsView.AddChidren(new Button() { X = Application.GetRealWidth(24), Width = Application.GetRealWidth(112), Height = Application.GetRealWidth(1), BackgroundColor = CSS_Color.DividingLineColor, }); } Button btnItem = new Button() { X = Application.GetRealWidth(24), Width = Application.GetRealWidth(128), Height = Application.GetRealHeight(44), Text = item.Value, TextColor = CSS_Color.FirstLevelTitleColor, SelectedTextColor = CSS_Color.MainColor, TextSize = CSS_FontSize.SubheadingFontSize, TextAlignment = TextAlignment.CenterLeft, IsSelected = item.Key == curItem }; itemsView.AddChidren(btnItem); btnItem.MouseUpEventHandler = (sender, e) => { fallbackAction?.Invoke(item.Key, item.Value); dialog.Close(); }; } dialogBodyView.MouseUpEventHandler = (sender, e) => { dialog.Close(); }; dialog.Show(); } } }