How to know when trackball is hidden?
I need to get even to know when a trackball is hidden.
I've created a subclass from ChartTrackballBehavior and am using OnTouchUp and OnTouchMove to determine whether the trackball is still visible. But it's not covering cases when the touch was cancelled. How can I receive reliable notification when the trackball becomes hidden?
public class CanHideTrackballBehaviour: ChartTrackballBehavior
{
public event EventHandler? TrackballClosed;
protected override void OnTouchUp(ChartBase chart, float pointX, float pointY)
{
base.OnTouchUp(chart, pointX, pointY);
TrackballClosed?.Invoke(this, EventArgs.Empty);
}
protected override void OnTouchMove(ChartBase chart, float pointX, float pointY)
{
base.OnTouchMove(chart, pointX, pointY);
if (!chart.SeriesBounds.Contains(pointX, pointY))
{
TrackballClosed?.Invoke(this, EventArgs.Empty);
}
}
}
Hi Maksym Shustov,
We regret to inform you that currently, there is no option to receive notifications on hide. Could you please explain your complete use case so that we can explore other possibilities to meet your requirements?
Please reach out if you need further assistance.
Best regards,
Arul Jenith B.
The chart is displayed inside scrollview and I want to prevent scrolling when user is interacting with trackball. Is there any way how I can achieve it?
Hi Maksym Shustov,
We suggest the following workaround to achieve your requirements. This involves adding a handler for Android that overrides the OnInterceptTouchEvent method, thereby disabling scrolling while interacting inside the chart control based on your requirements. Below is a code snippet for your reference:
public class ScrollViewEnableHandler : ScrollViewHandler { public ScrollViewEnableHandler() { Mapper.AppendToMapping( nameof(IScrollView.IsEnabled), (handler, view) => ((MauiScrollViewEnable)handler.PlatformView) .UpdateIsEnabled(view.IsEnabled)); }
protected override MauiScrollView CreatePlatformView() { var scrollView = new MauiScrollViewEnable( new ContextThemeWrapper(MauiContext!.Context, ResourceConstant.Style.scrollViewTheme), null!, ResourceConstant.Attribute.scrollViewStyle) { ClipToOutline = true, FillViewport = true, };
return scrollView; } }
public class MauiScrollViewEnable : MauiScrollView { private bool _disableScrolling;
public override bool OnInterceptTouchEvent(MotionEvent? ev) { if (ev == null) return false;
if (ev.Action == MotionEventActions.Up) { if (!_disableScrolling) // using this you can enable or disable based on your requirement. { return true; } } return false; } } |
Adding this Handler to our MAUI application:
public static class MauiProgram { public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .UseMauiApp<App>() .ConfigureSyncfusionCore() .ConfigureMauiHandlers(handlers => { #if ANDROID handlers.AddHandler<ScrollView, ScrollViewEnableHandler>(); #endif }); . . . } } |
For a clear understanding of creating the Scrollview handler and adding it to the application. You can refer the link provided below.
Link: Disabling Scrolling on Android
Here we have attached a modified sample for your convenience. You can refer to it.
If you have any further inquiries or require assistance, please don't hesitate to reach out. We're here to assist you.
Best regards,
Arul Jenith B.
Attachment: MauiScrollViewChartSample_c05aaf5f.zip
I have a very similar code for Android. The problem is still the same, when should I disable the scrolling. I see that's based on IsEnabled property. When should I disable the scrolling?
Hi Maksym Shustov,
To clarify, when interactions occur with a child view, the parent view (ScrollView) interaction should not trigger. This is expected behavior. However, this contributes to the current issue: when interacting with the chart (child) inside the ScrollView (parent), scrolling also occurs. This is a framework-level issue.
Issue 1: https://github.com/dotnet/maui/issues/9827
Issue 2: https://github.com/dotnet/maui/issues/7814
To address this issue, we provide a workaround using a handler and OnInterceptTouchEvents. When interacting inside the chart, scrolling is disabled; outside the chart, scrolling works as expected in the provided sample.
We have attached the sample for your reference. If you need any further assistance, feel free to contact us.
Regards,
Arul Jenith B.
Attachment: MauiScrollViewChartSample_196306_81c78853.zip
- 5 Replies
- 2 Participants
-
MS Maksym Shustov
- Mar 7, 2025 07:10 PM UTC
- Mar 12, 2025 12:19 PM UTC