c# - Exactly which object have I clicked on? -
<border name="firstborder" grid.column="0" grid.row="0" borderbrush="black" borderthickness="1"> </border> <border name="secondborder" grid.column="1" grid.row="0" borderbrush="black" borderthickness="1"> </border> <border name="thirdborder" grid.column="0" grid.row="1" borderbrush="black" borderthickness="1"> </border> <border name="fourthborder" grid.column="1" grid.row="1" borderbrush="black" borderthickness="1"> </border>
i have above 4 border objects. want use visual hit testing determine 1 of these have clicked on.
// clear contents of list used hit test results. hitresultslist.clear(); // set callback receive hit test result enumeration. visualtreehelper.hittest(this, null, new hittestresultcallback(myhittestresult), new pointhittestparameters(point)); // perform actions on hit test results list. if (hitresultslist.count > 0) { console.writeline("number of visuals hit: " + hitresultslist.count); } visual visual = hitresultslist[1]; console.writeline("to string " + visual.tostring()); if ( visual.equals(secondborder) ) console.writeline("2nd border "); if (visual.equals(firstborder)) console.writeline("first border "); if (visual.equals(thirdborder)) console.writeline("third border "); if (visual.equals(fourthborder)) console.writeline("4th border ");
the debugger tells me visual hit test has returned border element in hitresultslist[1]. want identify 1 of 4 border objects it. how can that?
try
console.writeline((border)visual.name);
to print name of item console. output should visible in visual studio output window.
Comments
Post a Comment