Suppose I wanted to do this, so I can find the current position of the mouse relative to a Visual
, without needing access to a specific mouse event:
<
There's a static method PresentationSource.FromVisual which:
Returns the source in which a provided Visual is presented.
I know this doesn't solve the underlying problem, but you could check that the Visual is connected to a PresentationSource before calling PointFromScreen
. It would prevent the exception, but you'd need to do some more investigation as to why it wasn't connected in the first place.