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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 做成一个存在于右上角的菜单控件
    /// </summary>
    public class TopRightMenuControl : FrameLayout
    {
        /// <summary>
        /// 框框控件
        /// </summary>
        private FrameLayout frameLine = null;
        /// <summary>
        /// 行高度
        /// </summary>
        private int RowHeight = 100;
        /// <summary>
        /// 行宽度
        /// </summary>
        private int RowWidth = 310;
        /// <summary>
        /// 线的高度
        /// </summary>
        private int LineHeight = 1;
        /// <summary>
        /// 菜单数计数
        /// </summary>
        private int menuCount = 0;
        /// <summary>
        /// 做成一个存在于右上角的菜单控件
        /// </summary>
        /// <param name="frame">父容器控件</param>
        /// <param name="i_RowCount">一共有几行</param>
        public TopRightMenuControl(FrameLayout frame, int i_RowCount)
        {
            //初始化画面的控件
            this.InitFormControl(frame, i_RowCount);
        }
 
        /// <summary>
        /// 添加菜单行
        /// </summary>
        /// <param name="TextValue">显示的文字</param>
        /// <param name="action">单击菜单执行的事件</param>
        /// <param name="pramter">调用action所传递的参数</param>
        /// <param name="closeOnClick">单击的时候,关闭菜单</param>
        public void AddRowMenu(string TextValue, Action<object> action, object pramter = null, bool closeOnClick = true)
        {
            ViewNormalControl btnLine = null;
            if (this.menuCount > 0)
            {
                //画线
                btnLine = new ViewNormalControl(Application.GetRealWidth(RowWidth), LineHeight);
                btnLine.Y = Application.GetRealHeight(RowHeight * this.menuCount) + this.menuCount * LineHeight;
                btnLine.BackgroundColor = UserCenterColor.Current.Line;
                frameLine.AddChidren(btnLine);
            }
            this.menuCount++;
 
            //显示文字
            var btnText = new ViewNormalControl(RowWidth, RowHeight, true);
            btnText.Text = TextValue;
            btnText.TextAlignment = TextAlignment.Center;
            if (btnLine != null)
            {
                btnText.Y = btnLine.Bottom;
            }
            frameLine.AddChidren(btnText);
            btnText.MouseUpEventHandler += (sender, e) =>
            {
                if (closeOnClick == true)
                {
                    this.RemoveFromParent();
                }
 
                if (action != null)
                {
                    action(pramter);
                }
            };
        }
 
        /// <summary>
        /// 初始化画面的控件
        /// </summary>
        /// <param name="frame">父容器控件</param>
        /// <param name="i_RowCount">一共有几行</param>
        private void InitFormControl(FrameLayout frame, int i_RowCount)
        {
            this.BackgroundColor = UserCenterColor.Current.DialogBackColor;
            this.MouseUpEventHandler += (sender2, e2) =>
            {
                //关闭自身
                this.RemoveFromParent();
            };
            frame.AddChidren(this);
 
            //一个框
            this.frameLine = new FrameLayout
            {
                X = Application.GetRealWidth(740),
                Y = Application.GetRealHeight(200),
                Width = Application.GetRealWidth(RowWidth),
                Height = Application.GetRealHeight(RowHeight * i_RowCount) + (i_RowCount - 1) * LineHeight,
                BackgroundColor = UserCenterColor.Current.White,
                Radius = 6,
                BorderColor = UserCenterColor.Current.TextFrameColor,
                BorderWidth = 1
            };
            this.AddChidren(frameLine);
        }
    }
}