wei
2021-01-11 b271bcceb1c4e718377ca86b6213816abcf7482a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
    public class ListCellDialog
    {
        /// <summary>
        /// 数据集合
        /// </summary>
        Dictionary<string, string> items = new Dictionary<string, string>();
        /// <summary>
        /// 当前选中目标
        /// </summary>
        string curItem = "";
        /// <summary>
        /// 回掉方法
        /// </summary>
        Action<string,string> fallbackAction;
 
 
 
        public ListCellDialog(Dictionary<string, string> list,string curItem,Action<string,string> fallbackAction)
        {
            items = list;
            this.curItem = curItem;
            this.fallbackAction = fallbackAction;
        }
 
        /// <summary>
        /// 加载在右边的弹窗
        /// </summary>
        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();
 
 
        }
 
 
    }
}