public bool AllowMouseLeftButtonDown(MouseButtonEventArgs e)
{
if(e == null)
{
throw new ArgumentNullException("e");
}
bool enabled = Control.IsEnabled;
if(enabled)
{
// Get the current position and time
DateTime now = DateTime.UtcNow;
Point position = e.GetPosition(Control);
// Compute the deltas from the last click
double timeDelta = (now - LastClickTime).TotalMilliseconds;
Point lastPosition = LastClickPosition;
double dx = position.X - lastPosition.X;
double dy = position.Y - lastPosition.Y;
double distance = dx * dx + dy * dy;
// Check if the values fall under the sequential click temporal
// and spatial thresholds
if(timeDelta < SequentialClickThresholdInMilliseconds &&
distance < SequentialClickThresholdInPixelsSquared)
{
// TODO: Does each click have to be within the single time
// threshold on WPF?
ClickCount++;
}
else
{
ClickCount = 1;
}
// Set the new position and time
LastClickTime = now;
LastClickPosition = position;
// Raise the event
IsPressed = true;
}
else
{
ClickCount = 1;
}
return enabled;
}