Draggable Line Annotation Question

Oystein Bjorke 10 year бұрын 0
This discussion was imported from CodePlex

seveland12 wrote at 2012-05-03 15:02:

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;
            };

 


objo wrote at 2012-05-03 15:57:

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?


seveland12 wrote at 2012-05-04 14:44:

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!