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