locked
UWP CarouselView, how to remove/hide navigation buttons RRS feed

  • Question

  • User395271 posted

    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...

    Friday, July 10, 2020 11:34 AM

Answers

  • User382871 posted

    To achieve this function, try to create a custom renderer to remove the 'button'. The carouselpage corresponds to the FlipView on uwp. For this requirement on FlipView, you can refer to the following link: https://social.msdn.microsoft.com/Forums/en-US/0ea7eaf4-3f11-4bcb-93f7-b5f6e6a02418/hiding-the-next-and-previous-buttons-of-a-flipview-programatically?forum=winappswithcsharp

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, July 10, 2020 2:51 PM

All replies

  • User382871 posted

    To achieve this function, try to create a custom renderer to remove the 'button'. The carouselpage corresponds to the FlipView on uwp. For this requirement on FlipView, you can refer to the following link: https://social.msdn.microsoft.com/Forums/en-US/0ea7eaf4-3f11-4bcb-93f7-b5f6e6a02418/hiding-the-next-and-previous-buttons-of-a-flipview-programatically?forum=winappswithcsharp

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, July 10, 2020 2:51 PM
  • User395271 posted

    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;
              }
         }
    
    Friday, July 10, 2020 4:41 PM