c# - WPF Get element at specific coordinates -


i have labels inside canvas, need label intersects coordinates x,y?

thanks!!

canvas.getleft(element), canvas.gettop(element) element's position. use actualwidth , actualheight form complete rectangle. can iterate through children of canvas foreach.

edit: codenaked pointed out elements might set setright or setbottom modified sample code:

foreach (frameworkelement nextelement in mycanvas.children) {     double left = canvas.getleft(nextelement);     double top = canvas.gettop(nextelement);     double right = canvas.getright(nextelement);     double bottom = canvas.getbottom(nextelement);     if (double.isnan(left))     {         if (double.isnan(right) == false)             left = right - nextelement.actualwidth;         else             continue;     }     if (double.isnan(top))     {         if (double.isnan(bottom) == false)             top = bottom - nextelement.actualheight;         else             continue;     }     rect elerect = new rect(left, top, nextelement.actualwidth, nextelement.actualheight);     if (myxy.x >= elerect.x && myxy.y >= elerect.y && myxy.x <= elerect.right && myxy.y <= elerect.bottom)     {         // add intersects list     } } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -