我在我的 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/