When mouse is rapidly dragged out of the window with left button pressed Mouse.DirectlyOver returns System.Windows.Controls.Grid instead of null.
Window.IsMouseOver returns true
new Rect(window.RenderSize).Contains(Mouse.GetPosition(window)) returns true
To reproduce that, simply add checking timer to MainWindow() in a blank wpf project like that:
public MainWindow()
{
InitializeComponent();
var timer = new System.Threading.Timer(state =>
Dispatcher.BeginInvoke(new Action(
() => Debug.WriteLine("Mouse.DirectlyOver = {0}", Mouse.DirectlyOver)
)),null,0,10);
}
When i drag out slowly, the values are correct.
Is there a workaround for that? What is the coorect way to determine mouse is out of the application?
Found a workaround.
On every tick I retrieve the mouse position with WinAPI’s
And then check in within borders of the window manually.