Search code examples
wpfmvvmlineoxyplot

Add a vertical line on MouseDown event


This seems very simple and straightforward, but I can't really get it to work.

I have a Line chart where I fill the data through binding to a List.

I want to create a command that adds a vertical line when the user presses the left mouse button. I would like to be able to do it in the ViewModel, but code-behind would work aswell.

Furthermore, I would like to set a limit of one vertical line per graph. So when the user clicks and there's already a vertical line, it should remove the old one and add the new one at the new position.


Solution

  • Easiest way to do this is to add event handlers:

    YourControl.Click += (sender, args) =>
    {
        // Your code here
    };
    

    Hope it helps