检查控件是否存在于wpf canvas的指定位置 [英] Check whether the control exists in specified position of wpf canvas

查看:218
本文介绍了检查控件是否存在于wpf canvas的指定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查WPF控件在指定的xy坐标中是否存在?

我具有canvas的左上角和左上角的值,因此通过提供此值,我必须检查此位置是否存在任何控件.

How can i check whether a WPF control exists in the specified xy coordinates?

I have the top and left value of canvas,so by giving this values i have to check whether in this position there is any control present or not.

推荐答案

bool ControlExistsAt(FrameworkElement e, Point p)
{
  return (p.X >= 0 && p.X <= e.ActualWidth) && (p.Y >= 0 && p.Y <= e.ActualHeight);
}



使用这种方法,您应该可以遍历canvas元素的每个子元素.



With this method you should be able to iterate over each child (e) of your canvas element.


这篇关于检查控件是否存在于wpf canvas的指定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆