title: In WPF, under what circumstances does Visual.PointFromScreen throw InvalidOperationException?
body: <p>Suppose I wanted to do this, so I can find the current position of the mouse relative to a <code>Visual</code>, without needing access to a specific mouse event:</p>
  
  <pre><code>public static Point GetMousePosition(this Visual relativeTo)
  {
      return relativeTo.PointFromScreen(GetMousePositionOnScreen());
  }
  </code></pre>
  
  <p>Sometimes (usually when I've just switched between two tab controls) <code>PointFromScreen</code> throws an <code>InvalidOperationException</code> with the message <em>This Visual is not connected to a PresentationSource.</em></p>
  
  <p>On looking at the properties available on <code>Visual</code> I can't see any relating to a <code>PresentationSource</code>.</p>
  
  <p>Given a <code>Visual</code>, how can I tell if it is going to throw that exception when I call <code>PointFromScreen</code> on it?</p>