Rectangle annotation click

Oystein Bjorke 10 jaar geleden 0
This discussion was imported from CodePlex

nickheath wrote at 2014-03-19 18:02:

I have multiple rectangle annotations on the plot, and I want to perform a hittest with the mouse position to check what annotation was clicked, how do I do this? I cannot find anything useful in the documentation.

Thanks

objo wrote at 2014-03-19 22:54:

I added the following example to the 'example browser':
            var annotation = new RectangleAnnotation() { MinimumX = 10, MaximumX = 60, MinimumY = 10, MaximumY = 20 };
            plotModel.Annotations.Add(annotation);

            int i = 0;
            annotation.MouseDown += (s, e) =>
            {
                annotation.Text = "Clicked " + (++i) + " times.";
                plotModel.InvalidatePlot(false);
            };
It has not yet been decided whether the mouse events should go...
https://oxyplot.codeplex.com/workitem/10132

nickheath wrote at 2014-03-20 10:39:

Thanks, that set me off down a different route:
var rect1 = new RectangleAnnotation();
rect1.Fill = GlassMainColor.ToOxyColor();
rect1.StrokeThickness = 1;
rect1.MinimumX = g1;
rect1.MaximumX = g2;
rect1.MinimumY = 0;
rect1.MaximumY = 100;

rect1.MouseDown += (s, e) =>
{
    SelectedPane = pane;
};
Where "SelectedPane" is a public property. On the setter of the property, the plot is re-drawn and if the CurrentPane == SelectedPane then the annotation renders in a different colour, and the SelectedPane object is exposed publicly.