wpf - 如何将平移命令绑定(bind)到 WPF 中 OxyPlot 的鼠标左键?

标签 wpf mvvm oxyplot

我在我的 WPF 应用程序中使用了 Oxyplot 控件。是否有一种 MVVM 友好的方式来重新连接右键单击平移操作以通过左键单击发生?

我当前的 wpf 代码是

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

最佳答案

我建议您创建一个用户控件:

我的UC.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);

    }
}

注意我已经用 MyPlotModel 替换了 Mydata,如果你想直接绑定(bind)数据,请改用 Plot。

它不是真正的 MVVM 友好,因为您必须使用此 UC,但您可以更改其 DataContext 以将其绑定(bind)到您的 ViewModel。

通常,您可以像这样绑定(bind)从您的 viewModel 创建的 Controller :
<oxy:PlotView x:Name="PlotView1" Model="{Binding **MyPlotModel**}" Controller="{Binding MyPlotController}"/>

但它似乎被窃听了,我不知道为什么。可能这会帮助你
https://github.com/oxyplot/oxyplot/issues/436
让我知道您是否可以在没有 UC 的情况下解决它。

关于wpf - 如何将平移命令绑定(bind)到 WPF 中 OxyPlot 的鼠标左键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31080733/

相关文章:

wpf - wpf mvvm中组合框的选择更改事件

c# - 如何更改 WPF 中的 View ?

wpf - 氧图 : ColumnSeries/BarSeries display value of each column

c# - 为什么我使用 UpdateSourceTrigger=PropertyChanged ,TwoWay 还不够?

c# - 每个单元格中具有不同 UserControl 的 WPF DataGrid

c# - 如何在asp.net核心 Razor 页面MVVM之间传递或引用模型

wpf - OxyPlot 图表中的可绑定(bind)注释

c# - 属性更改时未调用按钮命令 CanExecute

.net - 在 WPF 中实例化用户控件时 PresentationFramework.dll 中的 System.IO.IOException

wpf - OxyPlot 图例项目管理