gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 10:54:59 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com