我对oxyplot有2个问题,由于它们很简单,我将它们放在一起:
我的情节在XAML中的定义如下:
<oxy:Plot>
<oxy:Plot.Axes>
<oxy:DateTimeAxis Title="Time" Position="Bottom" StringFormat="HH:mm:ss" />
<oxy:LinearAxis Title="Temperature" Position="Left" Key="Temperature" />
<oxy:LogarithmicAxis Title="Pressure" Position="Right" Key="Pressure" />
</oxy:Plot.Axes>
<oxy:Plot.Series>
<oxy:LineSeries Title="Temperature" ItemsSource="{Binding Temperatures, Mode=OneWay}" DataFieldY="Temperature" YAxisKey="Temperature" />
<oxy:LineSeries Title="Pressure" ItemsSource="{Binding Pressures, Mode=OneWay}" DataFieldY="Pressure" YAxisKey="Pressure" />
</oxy:Plot.Series>
</oxy:Plot>
答案 0 :(得分:0)
通过XAML添加自定义控制器似乎是不可能的,因此我使用System.Windows.Interactivity.Behavior
来编辑绘图的控制器,而无需编写代码。
行为定义如下:
public class CustomControllerPlotBehavior : System.Windows.Interactivity.Behavior<Plot>
{
protected override void OnAttached()
{
AssociatedObject.Loaded += OnLoaded;
}
protected override void OnDetaching()
{
AssociatedObject.Loaded -= OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
CustomizeController(AssociatedObject.ActualController);
}
private void CustomizeController(IPlotController controller)
{
controller.UnbindAll();
// actual changes to the controller
controller.BindMouseDown(OxyMouseButton.Left, OxyModifierKeys.Shift, PlotCommands.ZoomRectangle);
controller.BindMouseDown(OxyMouseButton.Left, OxyModifierKeys.Control, PlotCommands.PanAt);
controller.BindMouseDown(OxyMouseButton.Left, PlotCommands.SnapTrack);
controller.BindKeyDown(OxyKey.Home, PlotCommands.Reset);
controller.BindMouseWheel(PlotCommands.ZoomWheel);
controller.BindMouseWheel(OxyModifierKeys.Control, PlotCommands.ZoomWheelFine);
}
}
在XAML中,可以这样使用行为:
<oxy:Plot>
<!-- Other plot settings -->
<i:Interaction.Behaviors>
<behaviors:CustomControllerPlotBehavior />
</i:Interaction.Behaviors>
</oxy:Plot>