【发布时间】:2011-01-10 09:14:44
【问题描述】:
假设我想这样做,这样我就可以找到鼠标相对于Visual 的当前位置,而无需访问特定的鼠标事件:
public static Point GetMousePosition(this Visual relativeTo)
{
return relativeTo.PointFromScreen(GetMousePositionOnScreen());
}
有时(通常当我刚刚在两个选项卡控件之间切换时)PointFromScreen 会抛出一个带有消息的InvalidOperationException 此视觉对象未连接到 PresentationSource。
在查看Visual 上的可用属性时,我看不到任何与PresentationSource 相关的内容。
给定一个Visual,当我对它调用PointFromScreen 时,我如何判断它是否会抛出该异常?
【问题讨论】: