黄学彪
2019-11-25 5727cf0b9b54da0a191dd1e23cb5abf21320fbff
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
using System;
using Shared.Common;
namespace Shared.Phone.Device.CommonForm
{
    /// <summary>
    /// 类似按下拥有短暂点亮效果的button
    /// </summary>
    public class SelectedStatuButton:Button
    {
        /// <summary>
        /// 选中状态停留时间 单位 毫秒 
        /// 默认200毫秒
        /// </summary>
        private static readonly int SelectedStatuTime = 200;
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Shared.SelectedStatuButton"/> class.
        /// </summary>
        public SelectedStatuButton(uint textColor = 0xFF666666, uint selectedTextColor = 0xFF000000)
        {
            MouseDownEventHandler += Button_MouseDownEvent;
            TextColor = textColor;
            SelectedTextColor = selectedTextColor;
        }
 
        
        /// <summary>
        /// 单击按下,实现短暂点亮选中效果
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="mouseEventArgs">The ${ParameterType} instance containing the event data.</param>
        private void Button_MouseDownEvent(object sender, MouseEventArgs mouseEventArgs)
        {
            bool statu = IsSelected;
            SetSeletedStatu();
            new System.Threading.Thread(() =>
            {
                System.Threading.Thread.Sleep(SelectedStatuTime);
                SetUnSelectedStatu();
                Application.RunOnMainThread(() =>
                {
                    IsSelected = statu;
                });
            })
            { IsBackground = true }.Start();
 
        }
        /// <summary>
        /// 设置选中状态
        /// </summary>
        public void SetSeletedStatu()
        {
            Application.RunOnMainThread(() =>
            {
                if (string.IsNullOrEmpty(UnSelectedImagePath) == false && string.IsNullOrEmpty(SelectedImagePath) == true)
                {
                    IsSelected = false;
                }
                else
                {
                    IsSelected = true;
                }
            });
        }
        /// <summary>
        /// 设置不选中状态
        /// </summary>
        public void SetUnSelectedStatu()
        {
            Application.RunOnMainThread(() =>
            {
                IsSelected = false;
            });
        }
    }
 
 
}