ScrollViewer GridView XAML

I am currently creating an application for Windows X XLL C #. On the page, I have a scrollviewer for horizontally scrolling and scrolling. I have several controls that work great with scorllviewer. But when you scroll and your cursor is on top of ListView / GridView, then this control will handle scrollnig instead of scrollviewer. This does not happen with scrolling, but with the help of the mouse scroll wheel it stops the scroll scroll. Does anyone know how to disable this behavior or have a workaround?

+5
source share
6 answers

After a long work with this problem, I decided to change my tactics. At least in my solution, I changed the internal GridView to just be an ItemsControl control. This way I can handle all the clicks / clicks, but still let the scrollbar work as expected.

Of course, this solution is not for everyone, because sometimes you need all the material for selection. But for me it worked, since I only need the click / tap element.

Hope this helps

+1
source

This is a problem that I see too. It does not exist by touch - it seems to happen only when using the mouse wheel. I don’t know yet about a workaround. I do not think there is one.

0
source

: msdn

:

XAML:

   <Grid Name="BaseElement">
        <ScrollViewer Name="MainScrollViewer" Style="{StaticResource HorizontalScrollViewerStyle}" VerticalScrollMode="Auto">
            <GridView />
            <GridView />
        </ScrollViewer>
    </Grid>
  • :

    BaseElement.AddHandler(PointerWheelChangedEvent, new PointerEventHandler(Bubble_PointerWheelChanged), true);
    
  • :

    private void Bubble_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
    {
        // Could walk up the tree to find the next SV or just have a reference like here:
        MainScrollViewer.ScrollToHorizontalOffset(MainScrollViewer.HorizontalOffset - e.GetCurrentPoint(null).Properties.MouseWheelDelta);
    }
    
0
source

I also had the same problem. Then I tried to remove the scrollbars from the Grid template, as mentioned in the section below. It worked great for me.

fooobar.com/questions/771814 / ...

0
source

The best solution ever.

public class CustomGridView : GridView
{
    protected override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        var sv = this.GetTemplateChild("ScrollViewer") as UIElement;
        if (sv != null)
            sv.AddHandler(UIElement.PointerWheelChangedEvent, new PointerEventHandler(OnPointerWheelChanged), true);
    }

    private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
    {
        e.Handled = false;
    }
}

More info: GridView in ScrollViewer

0
source

1. Add this code to View.cs:

  private void ThumbnailViewer_OnMouseWheel(object sender, MouseWheelEventArgs e)
    {
        ThumbnailViewerScroller.ScrollToHorizontalOffset(ThumbnailViewerScroller.HorizontalOffset - e.Delta);
    }

Code 2.add in Xaml:

  <ScrollViewer
            x:Name="ViewerScroller"               
            MouseWheel="ThumbnailViewer_OnMouseWheel">
<StackPanel>
...
</StackPanel>
</ScrollViewer>
0
source

All Articles