0

I need a mouse click event in my silver light project and I know we need to simulate it ourself if the object is not button. lets say I want mouseclick for my img... How exactly can we track time between mousedown and mouseup and say if the time between them is less than 300m, we have a mouse click?

Daniel
  • 3,322
  • 5
  • 30
  • 40

1 Answers1

2

Handle the MouseLeftButtonDown and MouseLeftButtonUp events for your image.

private DateTime? startClick;

private void image1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    startClick = DateTime.Now;
}

private void image1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    var clickDuration = DateTime.Now - startClick;

    if (startClick != null && clickDuration < TimeSpan.FromMilliseconds(300))
    {
        MessageBox.Show("Less than 300ms!");
    }

    startClick = null;
}
Kevin Aenmey
  • 13,259
  • 5
  • 46
  • 45