jhaefliger

Bug with Visuals on map?

Discussion created by jhaefliger on Oct 18, 2011
Latest reply on Oct 20, 2011 by JNery-esristaff
I am trying to do provide some in-place editing in some of our custom symbols. So I have to put a textbox inside the symbol templates. Doing so results in crashes in some ArcGis APIs. I tracked down at least one bug:

GraphicsLayer.FindGraphicsInHostCoordinates(Rect) is buggy if the intersectingRect contains the textbox. Here???s why. It first uses VisualTreeHelper.HitTest to find the visuals inside the rectangle, but then casts them to UIElement:
elements.Add(result.VisualHit as UIElement)
The problem with that line is that some Visuals are not UIElement, e.g. when using textboxes. Because of that a null is inserted inside the result.

The next step is calling the private GetGraphicsFromUIElements() method, which doesn???t handle nulls and crashes with a NullReferenceException.

I suspect that GraphicsLayer.FindGraphicsInHostCoordinates(Point) would crash as well since it tries to perform a direct cast:
(UIElement)hitTestResult.VisualHit
which would surely result in an InvalidCastException.

Outcomes