How to bind the Panning command to the left mousebutton for OxyPlot in WPF?

1.1k views Asked by At

I am using an Oxyplot control in my WPF application. Is there a MVVM friendly way to re-wire the right click pan action to happen with a left click?

My current wpf code is

<oxy:PlotView Model="{Binding MyData}" Grid.Column="1" Grid.Row="0" />
1

There are 1 answers

1
MaX On BEST ANSWER

I'd suggest you to create a User Control:

myUC.xaml

<oxy:PlotView x:Name="PlotView1" Model="{Binding **MyPlotModel**}" />

myUC.xaml.cs

public partial class myUC : UserControl
{
    public myUC()
    {
        InitializeComponent();
        PlotView1.Controller = new OxyPlot.PlotController();
        /* Events Managment */
        PlotView1.Controller.UnbindAll();
        PlotView1.Controller.BindMouseDown(OxyMouseButton.Left, PlotCommands.PanAt);

    }
}

Note I have replaced Mydata by MyPlotModel, if you want to directly bind data use Plot instead.

It is not really MVVM friendly because you'll have to use this UC, but you can change its DataContext to bind it to your ViewModel.

Normally you could bind a Controller created from your viewModel just like this:

<oxy:PlotView x:Name="PlotView1" Model="{Binding **MyPlotModel**}" Controller="{Binding MyPlotController}"/>

But it seems bugged and I could not figure out why. May be this will help you https://github.com/oxyplot/oxyplot/issues/436 Let me know if you can solve it without UC.