【发布时间】:2015-06-26 19:25:50
【问题描述】:
我在我的 WPF 应用程序中使用了 Oxyplot 控件。是否有一种 MVVM 友好的方式来重新连接右键单击平移操作以通过左键单击发生?
我当前的 wpf 代码是
<oxy:PlotView Model="{Binding MyData}" Grid.Column="1" Grid.Row="0" />
【问题讨论】:
我在我的 WPF 应用程序中使用了 Oxyplot 控件。是否有一种 MVVM 友好的方式来重新连接右键单击平移操作以通过左键单击发生?
我当前的 wpf 代码是
<oxy:PlotView Model="{Binding MyData}" Grid.Column="1" Grid.Row="0" />
【问题讨论】:
我建议你创建一个用户控件:
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 的情况下解决它。
【讨论】: