Reputation: 129
I use OxyPlot in my work to show some information. And I need to change the default tooltip which you can see after clicking on some point in the graph.
Currently, I have the test WPF window with a simple linear series. I've changed the template for the tooltip to display some text and button.
My controllers:
public class PlotViewTest : PlotView
{ }
public class TestTracker : TrackerControl
{
public TestTracker()
{
CanCenterHorizontally = false;
CanCenterVertically = false;
}
}
My WPF window code:
<controlers:PlotViewTest Model="{Binding MyModel}">
<controlers:PlotViewTest.DefaultTrackerTemplate>
<ControlTemplate>
<controlers:TestTracker Position="{Binding Position}">
<Grid Margin="15">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="5" Text="Hello world!"/>
<Button Grid.Row="1" Margin="5" Content="Start"/>
</Grid>
</controlers:TestTracker>
</ControlTemplate>
</controlers:PlotViewTest.DefaultTrackerTemplate>
</controlers:PlotViewTest>
My WPF window:
But there are a few behaviors that I want to change.
How can change these two behaviors??
Upvotes: 0
Views: 2180
Reputation: 18153
You could achieve the objectives by writing a Custom TrackerManipulator which overrides the Completed
action of the Tracker. For example
public class StaysOpenTrackerManipulator : TrackerManipulator
{
public StaysOpenTrackerManipulator(IPlotView plotView) : base(plotView)
{
Snap = true;
PointsOnly = true;
}
public override void Completed(OxyMouseEventArgs e)
{
// Do nothing
}
}
By setting Snap
and PointsOnly
properties to true, you ensure that the Tracker is opened only when selecting the points and not elsewhere (line/outside).
You could bind the Custom TrackerManipulator to PlotView using a PlotController.
// Property
public PlotController CustomPlotController { get; set; }
// Assign Value for CustomPlotController
var customController = new PlotController();
customController.UnbindAll();
customController.BindMouseDown(OxyMouseButton.Left, new DelegatePlotCommand<OxyMouseDownEventArgs>((view, controller, args) =>
controller.AddMouseManipulator(view, new StaysOpenTrackerManipulator(view), args)));
CustomPlotController = customController;
And in Xaml
<controlers:PlotViewTest Model="{Binding MyModel}" Controller="{Binding CustomPlotController}">
Upvotes: 3