So I really like the clean interface of just having my line chart with a trackball showing all data points as the mouse is moved, however, it seems there is no way of pausing or freezing the trackball and because of this a user is unable to save or print the chart while including the information currently being shown by the trackball.
Hopefully this is something easy I am just overlooking.
|
<chart:SfChart.Behaviors>
<local:ChartTrackBallBehaviorExt x:Name="trackball" />
</chart:SfChart.Behaviors> |
|
public class ChartTrackBallBehaviorExt : ChartTrackBallBehavior
{
public Point TrackballPoint { get; set; }
public void Show(float x, float y)
{
IsActivated = true;
var point = new Point(x - this.ChartArea.SeriesClipRect.Left, y);
SetNativeInternalProperty(typeof(ChartTrackBallBehavior), this, point, "CurrentPoint");
base.OnPointerPositionChanged();
InvokeInternalMethod(typeof(ChartTrackBallBehavior), this, "Activate", IsActivated);
}
internal void SetNativeInternalProperty(Type type, object obj, object value, string propertyName)
{
var properties = type.GetRuntimeProperties();
foreach (var item in properties)
{
if (item.Name == propertyName)
{
item.SetValue(obj, value);
break;
}
}
}
public object InvokeInternalMethod(Type type, object obj, string methodName, params object[] args)
{
var method = type.GetTypeInfo().GetDeclaredMethod(methodName);
return method != null ? method.Invoke(obj, args) : null;
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
IsActivated = true;
Point point = e.GetPosition(this.ChartArea);
var trackball1 = (this.ChartArea.Behaviors[0] as ChartTrackBallBehaviorExt);
var diff1 = Math.Abs(trackball1.TrackballPoint.X - point.X);
UpdateTrackballPosition(trackball1, point);
}
private void UpdateTrackballPosition(ChartTrackBallBehaviorExt trackball, Point point)
{
trackball.TrackballPoint = point;
trackball.SetNativeInternalProperty(typeof(ChartTrackBallBehavior), this, point, "CurrentPoint");
trackball.OnPointerPositionChanged();
trackball.InvokeInternalMethod(typeof(ChartTrackBallBehavior), this, "Activate", IsActivated);
trackball.Show((float)point.X, (float)point.Y);
}
protected override void OnLayoutUpdated()
{
// base.OnLayoutUpdated();
}
} |
That worked exactly as expected, thank you since I never would have figured that out.