public static bool IsMouseWithin(this MouseButtonEventArgs e, FrameworkElement element)
{
// Setup initial conditions.
if (e == null) return false;
if (element == null) return false;
var position = e.GetPosition(element);
// Check bounds.
if (position.X < 0 || position.Y < 0) return false;
return position.X <= element.ActualWidth && position.Y <= element.ActualHeight;
}
}