Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

UWP CarouselView, how to remove/hide navigation buttons

SergTomcatSergTomcat Member ✭✭

When mouse over a CarouselView, navigation buttons appear on the sides of the screen.

Obviously, because it's not comfortable to do a swipe gesture with mouse.

Is there a way to hide them?
I want to implement custom buttons for navigation.

Ideally is to remove swipe gestures and side buttons, like InputTransparent parameter does. Ideally...

Best Answer

Answers

  • SergTomcatSergTomcat Member ✭✭
    edited July 10

    Thank you for directions. Working as intended.

    By the way, is there any way to prevent user swipe gestures in Droid and iOS?

    Here's the code if anyone stumble upon that problem:

         public sealed class PumpedCarouselPageRenderer : CarouselPageRenderer
         {
              protected override void OnElementChanged(ElementChangedEventArgs<CarouselPage> e)
              {
                   var curElement = ContainerElement as FlipView;
                   curElement.Loaded += FlipView_Loaded;
              }
    
              private void FlipView_Loaded(object sender, RoutedEventArgs e)
              {
                   foreach (string ControlId in new string[] { "PreviousButtonHorizontal", "NextButtonHorizontal" })
                   {
                        Button navBtn = FindVisualChild<Button>((FlipView)sender, ControlId);
                        if (navBtn != null)
                        {
                             navBtn.Opacity = 0.0;
                             navBtn.IsHitTestVisible = false;
                        }
                   }
              }
    
              private T FindVisualChild<T>(DependencyObject obj, string name) where T : FrameworkElement
              {
                   for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
                   {
                        DependencyObject child = VisualTreeHelper.GetChild(obj, i);
                        if (child is T && ((FrameworkElement)child).Name == name)
                             return (T)child;
                        else
                        {
                             T childOfChild = FindVisualChild<T>(child, name);
                             if (childOfChild != null)
                                  return childOfChild;
                        }
                   }
                   return null;
              }
         }
    
Sign In or Register to comment.