Button in Tracker? #1981
-
Is it possible to add a button with OnClick/ Command functionality to a tracker? If yes, how? I am panning to have a button in the tracker of a ScatterSeries. If you click the button, another plot will be visible with more information about the point. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 17 replies
-
It may be possible with some platforms, e.g. there are examples for custom trackers for WPF: https://github.com/oxyplot/oxyplot/blob/develop/Source/Examples/WPF/WpfExamples/Examples/CustomTrackerDemo/MainWindow.xaml Note that you'll need a custom plot controller in order to keep the tracker open after clicking: https://github.com/oxyplot/oxyplot/blob/899ea5b3baf3d2010680f2e607ad5281e3f190e5/Source/Examples/WPF/SimpleDemo/CustomPlotController.cs In general, may be best to handle clicking of the series manually without the tracker, as it sounds like you won't really be using it as a tracker any more, and that should be achievable on any platform (WinForms, for example, doesn't support custom trackers) |
Beta Was this translation helpful? Give feedback.
-
With a lot of help from @VisualMelon I finally managed to create a tracker with working buttons inside. To summarize:
internal class StaysOpenTrackerManipulator : OxyPlot.TrackerManipulator
{
public StaysOpenTrackerManipulator(IPlotView plotView) : base(plotView)
{
Snap = true;
PointsOnly = true;
}
public override void Started(OxyMouseEventArgs e)
{
/*
* Close tracker when clicking. This avoids wrong shaping of the tracker
* in case it's text is of different length for different points. Additionally,
* one can close the tracker like this by clicking somewhere else.
*/
PlotView.HideTracker();
base.Started(e);
}
public override void Completed(OxyMouseEventArgs e)
{
// Do nothing to avoid tracker closing.
}
} and add it to the plot controller: CustomPlotController.BindMouseDown(mouseButton, new DelegatePlotCommand<OxyMouseDownEventArgs>((view, controller, args) =>
controller.AddMouseManipulator(view, new StaysOpenTrackerManipulator(view), args)));
public class RtpOptimizationPlotView : PlotView
{
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
grid.Children.RemoveAt(grid.Children.Count - 1);
}
}
<UserControl
...
x:Name="RtOptimizationUserControl">
<views:RtpOptimizationPlotView
Model="{Binding OptimizationPlotModel, Mode=TwoWay}"
Controller="{Binding CustomPlotController}">
<views:RtpOptimizationPlotView.DefaultTrackerTemplate>
<ControlTemplate>
<oxy:TrackerControl
IsHitTestVisible="True"
Position="{Binding Position}" LineExtents="{Binding PlotModel.PlotArea}"
BorderThickness="1">
<oxy:TrackerControl.Background>
<SolidColorBrush Color="LightBlue" />
</oxy:TrackerControl.Background>
<oxy:TrackerControl.Content>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding}" Margin="7"/>
<StackPanel Orientation="Horizontal">
<Button
Command="{Binding DataContext.FirstButtonsCommand, ElementName=RtOptimizationUserControl}">Button 1</Button>
<Button
Command="{Binding DataContext.SecondButtonsCommand, ElementName=RtOptimizationUserControl}">Button 2</Button>
</StackPanel>
</StackPanel>
</oxy:TrackerControl.Content>
</oxy:TrackerControl>
</ControlTemplate>
</views:RtpOptimizationPlotView.DefaultTrackerTemplate>
</views:RtpOptimizationPlotView>
</UserControl> Thanks a lot to @VisualMelon for all your help! |
Beta Was this translation helpful? Give feedback.
With a lot of help from @VisualMelon I finally managed to create a tracker with working buttons inside. To summarize:
TrackerManipulator
: