Silverlight 没有提供双击事件,所以需要通过判断两次点击的时间来模拟双击事件
下面的代码,做个参考。
cellBtn.Click += new RoutedEventHandler(cellBtn_Click);
//cellBtn.MouseLeftButtonUp += new MouseButtonEventHandler(cellBtn_MouseLeftButtonUp);
//cellBtn.MouseLeftButtonDown += new MouseButtonEventHandler(cellBtn_MouseLeftButtonUp);
//cellBtn.MouseEnter += new MouseEventHandler(cellBtn_MouseLeftButtonUp);
void cellBtn_MouseLeftButtonUp(object sender, MouseEventArgs e)
{
DateTime b = DateTime.Now;
long c = TimeDiff(b, _timeLastLeftButtonUp);
_timeLastLeftButtonUp = b;
if (c < 300)
{
HtmlWindow html = HtmlPage.Window;
html.Alert("双击");
}
else
{
}
}
void cellBtn_Click(object sender, RoutedEventArgs e)
{
//string neDetail = (sender as Button).Content.ToString();
//HtmlWindow html = HtmlPage.Window;
//html.Alert(neDetail);
}
/// <summary>
/// 计算时间差
/// </summary>
/// <param name="t">时间1</param>
/// <param name="t2">时间2</param>
/// <returns>返回值:时间差(毫秒为单位)</returns>
private long TimeDiff(DateTime t, DateTime t2)
{
long lReturn = -1;
System.TimeSpan NowValue = new TimeSpan(t.Ticks);
System.TimeSpan TimeValue = new TimeSpan(t2.Ticks);
System.TimeSpan DateDiff = TimeSpan.Zero;
try
{
//计算时间差
//DateDiff = TimeValue.Subtract(NowValue).Duration();
DateDiff = NowValue.Subtract(TimeValue);
int hours = DateDiff.Hours;
int minutes = DateDiff.Minutes;
int seconds = DateDiff.Seconds;
int milliseconds = DateDiff.Milliseconds;
string TimeDiff = hours.ToString() + ":"
+ minutes.ToString() + ":"
+ seconds.ToString() + "."
+ milliseconds.ToString();
//Program.log.WriteLog("时间差:"+TimeDiff, System.DateTime.Now.ToString(), Orid.Log.LogManagerBase.LogMode.logNormal);
lReturn = hours * 3600 * 1000
+ minutes * 60 * 1000
+ seconds * 1000
+ milliseconds;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
return lReturn;
}