Getting X/Y Value from Annotation (Xamarin Android)


I’ve wired up a touch event to slide an annotation by calling:


This works fine, but I can’t get the position on the axis after moving it.  I thought that just calling annotation.XValue would return it, but it retains whatever the XValue was when I created the annotation (or moved it using annotation.XValue = value).

Is there a way to get the value of the annotation, or a different way I should be moving the annotation (having only the screen x/y coordinate and not the chart x/y axis position)?



I notice that you are setting the x value on the Annotation’s Android View rather than our Annotation object itself. I appreciate that due to the touch event you are working with, you need to use pixel values rather than data values to set your x value.

I recommend that you convert your pixel values to data values, and set the x, in data terms on the Annotation object using annotation.XValue = value. By using this approach you should be able to then retrieve the xValue from the Annotation using annotation.XValue.

Our Axis classes contain some handy methods to help you convert a value from pixel terms to data terms, and vice-versa. Please see some helpful links below:

I hope that you find this helpful. 

Thanks, Kai.


Thanks Kai!  I couldn’t find the GetPixelValueForUserValue and GetUserValueForPixelValue functions.  That’s exactly what I needed.  And changing the methods to set the annotation X/Y instead of the annotation view X/Y makes a lot of sense.



Hi Jamie.

I’m glad I was able to help.

If you have any more questions please do ask.