黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone
{
    /// <summary>
    /// 点击按钮类的共通
    /// </summary>
    public class ClickButtonCommon : ButtonBase
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 是否启用点亮功能(默认启用)
        /// </summary>
        public bool UseClickStatu = true;
        /// <summary>
        /// 原来的背景色(迫不得己,这个东西需要开放出去,设置一次之后将不会再设置)
        /// </summary>
        public uint oldBackgroundColor = 0;
        /// <summary>
        /// 点击状态的背景色(迫不得己,这个东西需要开放出去,默认使用底层设置的)
        /// </summary>
        public uint clickStatuColor = UserCenterColor.Current.ButtonClickStatuColor;
        /// <summary>
        /// 是否处于选择状态
        /// </summary>
        private bool isSelcetStatu = false;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 单击按钮类的共通(初始值:拥有点亮功能,白色字体,黑色背景,文字居中)
        /// </summary>
        public ClickButtonCommon()
        {
            this.TextColor = UserCenterColor.Current.White;
            this.BackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
            this.TextAlignment = TextAlignment.Center;
 
            this.ButtonDownClickEvent += this.Button_MouseDownEvent;
        }
 
        #endregion
 
        #region ■ 控件点亮特效_______________________
 
        /// <summary>
        /// 单击按下事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_MouseDownEvent(object sender, MouseEventArgs e)
        {
            if (this.UseClickStatu == false)
            {
                //永久移除
                this.ButtonDownClickEvent -= Button_MouseDownEvent;
                return;
            }
            if (base.CanClick == false || isSelcetStatu == true)
            {
                //控件不能点击,或者当前处于选择状态,则不能触发
                return;
            }
            if (this.oldBackgroundColor == 0)
            {
                this.oldBackgroundColor = this.BackgroundColor;
            }
            //设置点击后的状态
            this.SetClickStatu();
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                System.Threading.Thread.Sleep(HdlControlResourse.StatuChangedWaitTime);
                HdlThreadLogic.Current.RunMain(() =>
                {
                    if (base.CanClick == false || isSelcetStatu == false)
                    {
                        //控件不能点击,或者当前处于非选择状态,则不能触发
                        return;
                    }
                    //设置非点击后的状态
                    this.SetNotClickStatu();
                });
            });
        }
 
        /// <summary>
        /// 设置点击后的状态
        /// </summary>
        public override void SetClickStatu()
        {
            this.isSelcetStatu = true;
            this.BackgroundColor = clickStatuColor;
        }
 
        /// <summary>
        /// 设置非点击后的状态
        /// </summary>
        public override void SetNotClickStatu()
        {
            this.isSelcetStatu = false;
            //设置不选择状态
            this.BackgroundColor = oldBackgroundColor;
        }
 
        #endregion
    }
}