public class TrackballBehaviorExt : ChartTrackballBehavior
{
private bool isLongPressActivated = false;
protected override void OnLongPress(float pointX, float pointY)
{
base.OnLongPress(pointX, pointY);
isLongPressActivated = true;
}
protected override void OnTouchUp(float pointX, float pointY)
{
base.OnTouchUp(pointX, pointY);
if (isLongPressActivated)
{
isLongPressActivated = false;
//Write your logic here
}
}
} |
public class ChartTrackballBehaviorExt : ChartTrackballBehavior
{
public ChartExt chart { get; set; }
public ChartTrackballBehaviorExt()
{
}
protected override void OnLongPress(float pointX, float pointY)
{
chart.TrackballVisible = true;
base.OnLongPress(pointX, pointY);
}
//For Android this override OnTouchUp will work fine after LongPress
protected override void OnTouchUp(float pointX, float pointY)
{
base.OnTouchUp(pointX, pointY);
}
//For iOS after long press TouchUp method called here
public void TouchUp(float pointX, float pointY)
{
if (chart != null)
{
chart.TrackballVisible = false;
//check your logic here for iOS
}
}
} |
class CustomChartRenderer : SfChartRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<SfChart> e)
{
base.OnElementChanged(e);
var formsChart = Element as Syncfusion.SfChart.XForms.SfChart;
for (int i = 0; i < formsChart.ChartBehaviors.Count; i++)
{
if (formsChart.ChartBehaviors[i] is Syncfusion.SfChart.XForms.ChartTrackballBehavior)
{
var formsTrackball = formsChart.ChartBehaviors[i] as
Syncfusion.SfChart.XForms.ChartTrackballBehavior; Control.Behaviors.Remove((SFChartBehavior)SfChartRenderer.GetNativeObject(typeof
(Syncfusion.SfChart.XForms.ChartTrackballBehavior), formsTrackball));
CustomTrackballBehavior customTrackball = new CustomTrackballBehavior();
customTrackball.FormsBehavior = formsTrackball;
var properties =
SfChartRenderer.GetPropertiesChanged(typeof(Syncfusion.SfChart.XForms.ChartTrackballBehavior),
formsTrackball);
foreach (var name in properties)
{
ChartTrackballBehaviorMapping.OnChartTrackballBehaviorPropertiesChanged(name,
formsTrackball, customTrackball);
}
SfChartRenderer.SetNativeObject(typeof(Syncfusion.SfChart.XForms.ChartTrackballBehavior),
formsTrackball, customTrackball);
Control.Behaviors.Insert(i, customTrackball);
}
}
}
}
public class CustomTrackballBehavior : ChartTrackballBehaviorHelper
{
public override void LongPressWithGestureRecognizer(UILongPressGestureRecognizer
longPressGestureRecognizer)
{
base.LongPressWithGestureRecognizer(longPressGestureRecognizer);
var locationInChart = longPressGestureRecognizer.LocationInView(Chart);
if (UIGestureRecognizerState.Ended == longPressGestureRecognizer.State)
{
(FormsBehavior as ChartTrackballBehaviorExt).TouchUp((float)locationInChart.X,
(float)locationInChart.Y);
}
}
} |
…
<local:ChartExt x:Name="chart" HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
….
<chart:SfChart.ChartBehaviors>
<local:ChartTrackballBehaviorExt chart="{x:Reference chart}"
ActivationMode="LongPress">
</local:ChartTrackballBehaviorExt>
</chart:SfChart.ChartBehaviors>
</local:ChartExt>
… |
I would like to request this to be implemented in the iOS component. We usually expect the same behavior in both platforms, and this surely is a "good to have" instead of having to implement custom renders.
att.
Hi Tavares,
Thank you for your request. We understand the importance of having consistent behavior across platforms and we will do our best to provide a solution that meets your needs. Our team will review the request and We will update you with more details as soon as possible. Thank you for your patience and understanding.
Regards,
Saravanan.
Hello Joan Caron,
We want to let you know that Xamarin.Forms does not currently offer support for Long press gesture recognize in trackball. And we have already considered Long press gesture recognize as a feature request and added it to our feature request list. You can track the status of this feature from the below feedback link.
Feedback: https://www.syncfusion.com/feedback/42348/long-press-gesture-recognizer-support-for-sfchart.
We will prioritize the features every release based on the demand, and we do not have an immediate plan to implement this since we committed to already planned work. So, this feature will be available for any of our upcoming release.
Please cast your vote to make it count, and if you have any more specifications/suggestions for the feature request, you can add them as a comment in the feedback portal.
Regards,
Sowndharya Selladurai.