0

The mouse events return the PlotController instead of the plotView or plotModel.

My question is how to access the plotModel from within the mouse event? Could someone tell me the idea behind this change from providing the plotmodel as source to now providing the plotcontroller? How would someone select all series or zoom in based on a mouse event having this plotcontroller as a source?

I would like to add an annotation triggered by an mouse event.

var plott = new PlotModel();
plott.MouseDown += Plott_MouseDown;

public void Plott_MouseDown(object sender, OxyMouseDownEventArgs e)
    {
        var plot = sender as PlotController;

        I NEED TO ACCESS THE PLOTMODEL TO ADD AN ANNOTATION

        plot.Annotations.Add(new RectangleAnnotation(){ MinimumX = e.Position.X, MinimumY = e.Position.Y });
    }
user2799180
  • 719
  • 1
  • 11
  • 29

1 Answers1

0

Give a name to your plot in xaml:

<oxy:PlotView x:Name="MyPlotView" .../>

Access it from code behind:

public void Plott_MouseDown(object sender, OxyMouseDownEventArgs e)
{
    MyPlotView.Model.Annotations.Add(new RectangleAnnotation(){ MinimumX = e.Position.X, MinimumY = e.Position.Y });
}
Jose
  • 1,857
  • 1
  • 16
  • 34
  • Thanks for that hint. Actually I know that I could access the plotview by name from the code behind but I'm using Caliburn Micro. To be more precise, a Caliburn Micro message. How to do it with that? Is there a way? For me the way of triggering some event from the code behind seems overengineering. – user2799180 Jun 14 '16 at 21:27