【问题标题】:How to bind the Panning command to the left mousebutton for OxyPlot in WPF?如何将平移命令绑定到 WPF 中 OxyPlot 的鼠标左键?
【发布时间】:2015-06-26 19:25:50
【问题描述】:

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

我当前的 wpf 代码是

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

【问题讨论】:

    标签: wpf mvvm oxyplot


    【解决方案1】:

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

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

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

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

    通常您可以像这样绑定从您的 viewModel 创建的控制器:

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

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

    【讨论】:

    • 我最终的做法与此非常相似,但 MVVM 少了一点。只需绑定到我的 VM 中的模型并在我的 VM 中使用自定义控制器构建模型。
    猜你喜欢
    • 2011-02-27
    • 1970-01-01
    • 2018-10-07
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-20
    相关资源
    最近更新 更多