优化更新代码,添加界面功能并整合
This commit is contained in:
37
WPFluent/Extensions/UiElementExtensions.cs
Normal file
37
WPFluent/Extensions/UiElementExtensions.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
|
||||
|
||||
namespace WPFluent.Extensions;
|
||||
|
||||
internal static class UiElementExtensions
|
||||
{
|
||||
private static int Get_X_LParam(IntPtr lParam) { return (short)(lParam.ToInt32() & 0xFFFF); }
|
||||
|
||||
private static int Get_Y_LParam(IntPtr lParam) { return (short)(lParam.ToInt32() >> 16); }
|
||||
|
||||
/// <summary>
|
||||
/// Do not call it outside of NCHITTEST, NCLBUTTONUP, NCLBUTTONDOWN messages!
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> if mouse is over the element. <see langword="false"/> otherwise.</returns>
|
||||
public static bool IsMouseOverElement(this UIElement element, IntPtr lParam)
|
||||
{
|
||||
// This method will be invoked very often and must be as simple as possible.
|
||||
if(lParam == IntPtr.Zero)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var mousePosScreen = new Point(Get_X_LParam(lParam), Get_Y_LParam(lParam));
|
||||
var bounds = new Rect(default, element.RenderSize);
|
||||
|
||||
Point mousePosRelative = element.PointFromScreen(mousePosScreen);
|
||||
|
||||
return bounds.Contains(mousePosRelative);
|
||||
} catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user