Display Trackball Info on Right Mouse Click
Environment
Product Version | 2019.2 624 |
Product | RadChartView for WPF |
Description
How to display the ChartView trackball on right mouse button click.
Solution
Subscribe to the PositionChanging event of the ChartTrackBallBehavior and reset the last position if the mouse right button wasn't not clicked. Then subscribe to the MouseRightButtonDown event of RadCartesianChart and set the Position property of the behavior manually.
<telerik:RadCartesianChart.Behaviors>
<telerik:ChartTrackBallBehavior PositionChanging="ChartTrackBallBehavior_PositionChanging" x:Name="trackballBehavior" />
</telerik:RadCartesianChart.Behaviors>
public partial class MainWindow : Window
{
private bool isManualPositionChange = false;
public MainWindow()
{
InitializeComponent();
this.trackballBehavior.Position = new Point(100, 321);
}
private void ChartTrackBallBehavior_PositionChanging(object sender, Telerik.Windows.Controls.ChartView.TrackBallPositionChangingEventArgs e)
{
if (e.NewPosition != e.PreviousPosition && !isManualPositionChange)
{
e.NewPosition = e.PreviousPosition;
}
this.isManualPositionChange = false;
}
private void RadCartesianChart_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
isManualPositionChange = true;
this.trackballBehavior.Position = e.GetPosition(this.chart);
}
}