Draggable Line Annotation Question

May 3, 2012 at 2:02 PM
Edited May 3, 2012 at 2:03 PM

I like the draggable annotations that I saw in the newest demo, so I decided to incorporate it into my WPF app. However, the demo code uses OxyPlot.LinearAnnotation, while my WPF code needs OxyPlot.Wpf.LinearAnnotation - is there a way to get the draggable behavior using the WPF class? I tried the following, which compiled, but didn't work...

(the variable redLineAnnotation is of type OxyPlot.Wpf.LinearAnnotation that I declare in my XAML view)

 

            redLineAnnotation.internalAnnotation.MouseDown += (s, e) =>
            {
                if (e.ChangedButton != OxyMouseButton.Left)
                {
                    return;
                }

                redLineAnnotation.StrokeThickness *= 5;
                mainPlot.RefreshPlot(false);
                e.Handled = true;
            };

            // Handle mouse movements (note: this is only called when the mousedown event was handled)
            redLineAnnotation.internalAnnotation.MouseMove += (s, e) =>
            {
                redLineAnnotation.X = redLineAnnotation.internalAnnotation.InverseTransform(e.Position).X;
                mainPlot.RefreshPlot(false);
                e.Handled = true;
            };
            redLineAnnotation.internalAnnotation.MouseUp += (s, e) =>
            {
                redLineAnnotation.StrokeThickness /= 5;
                mainPlot.RefreshPlot(false);
                e.Handled = true;
            };

 

May 3, 2012 at 2:57 PM
Edited May 3, 2012 at 3:01 PM

Your code looks ok, need to debug this to see what is wrong.

The WPF elements are a bit behind the platform-indepent elements, but I plan to add the missing properties and classes soon. I hope also the events can be available from WPF, but they should not be confused with the WPF mouse events...

If you are creating your plot in code, did you consider creating a PlotModel instead of declaring everything in XAML?

May 4, 2012 at 1:44 PM

Thanks for the feedback; I'm really looking forward to being able to draw out the full feature set of OxyPlot in WPF. I am so glad I found your project - WPF Toolkit's charting library was so unwieldy and borderline ill-conceived (you practically have to plan a mission to the moon to implement any new features using it!) - OxyPlot has really been a breath of fresh air. Thanks again!