如何在窗口中找到 wpf 元素的位置
我需要能够在应用程序窗口上找到 WPF 元素的位置,以便我可以在包含该元素的窗口的屏幕截图/图像捕获上围绕特定元素绘制一个矩形。
这是针对我正在开发的 VS 编码 UI 框架,该框架在发生错误时具有窗口捕获或元素捕获到图像的功能。我想将这两者结合起来,并有一个窗口捕获,显示错误元素周围的红色矩形。
很多论坛都有关于此问题的答案,但他们提到了 TranslatePoint。使用 Visual Studio 和 Microsoft 的 UITesting Coded UI WpfControls 时我看不到这一点。有人知道如何解决这个问题吗?
I need to be able to find the location of a WPF element on an application window so i can then draw a rectangle around the specific element on a screenshot/image capture of the window containing this element.
This is for a VS Coded UI Framework i am developing that has window captures or element capture to an image when an error occurs. I want to combine these two and have a window capture that shows a red rectangle around the element in error.
Alot of forums have answers around this, but they refer to TranslatePoint. I cannot see this when working with Visual Studio and Microsofts UITesting Coded UI WpfControls. Anyone know how to get around this??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TranslatePoint 是在
UIElement< 上定义的/代码>。任何
UIElement
都应该公开它。我怀疑问题在于 WpfControl 不是 WPF
UIElement
。您应该能够使用它的 BoundedRectangle< /a> 属性来获取正确的周围矩形,而不是UIElement
上的 TranslatePoint。TranslatePoint is defined on
UIElement
. AnyUIElement
should expose this.I suspect the problem is that WpfControl is not a WPF
UIElement
. You should be able to use it's BoundedRectangle property to get the proper surrounding rectangle instead of TranslatePoint on aUIElement
.切勿使用坐标。相反,获取控件并使用
DrawHighlight()
方法。这将在控件外部绘制一个蓝色矩形。Never use coordinates. Instead, get the control and use the
DrawHighlight()
method. This will draw a blue rectangle outside the control.